import*as e from"../../../../core/common/common.js";import*as t from"../../../../core/i18n/i18n.js";import*as i from"../../../../core/platform/platform.js";import*as s from"../../../components/render_coordinator/render_coordinator.js";import*as r from"../../legacy.js";import*as n from"../../../../models/trace/trace.js";import*as o from"../../theme_support/theme_support.js";import*as a from"../../../../core/host/host.js";import*as l from"../../../../core/sdk/sdk.js";import*as h from"../../../../models/bindings/bindings.js";import*as d from"../../../../models/workspace/workspace.js";import*as c from"../source_frame/source_frame.js";import*as m from"../../../components/helpers/helpers.js";import*as u from"../../../lit-html/lit-html.js";var g={cssContent:".chart-viewport-v-scroll{position:absolute;top:0;right:0;bottom:0;overflow-x:hidden;z-index:200;padding-left:1px}.chart-viewport-v-scroll.always-show-scrollbar{overflow-y:scroll}:host-context(.platform-mac) .chart-viewport-v-scroll{right:2px;top:3px;bottom:3px}:host-context(.platform-mac) ::-webkit-scrollbar{width:8px}:host-context(.platform-mac) ::-webkit-scrollbar-thumb{background-color:var(--color-scrollbar-mac);border-radius:50px}:host-context(.platform-mac) .chart-viewport-v-scroll:hover::-webkit-scrollbar-thumb{background-color:var(--color-scrollbar-mac-hover)}:host-context(.overlay-scrollbar-enabled) ::-webkit-scrollbar{width:10px}:host-context(.overlay-scrollbar-enabled) ::-webkit-scrollbar-thumb{background-color:var(--color-scrollbar-other)}:host-context(.overlay-scrollbar-enabled) .chart-viewport-v-scroll:hover::-webkit-scrollbar-thumb{background-color:var(--color-scrollbar-other-hover)}.chart-viewport-selection-overlay{position:absolute;z-index:100;background-color:var(--color-selection-highlight);border-color:var(--color-selection-highlight-border);border-width:0 1px;border-style:solid;pointer-events:none;top:0;bottom:0;text-align:center}.chart-viewport-selection-overlay .time-span{white-space:nowrap;position:absolute;left:0;right:0;bottom:0}"};let p=null;function f(){if(p)return p;const e=getComputedStyle(document.body);return p=e.fontFamily?e.fontFamily:a.Platform.fontFamily(),p}var v=Object.freeze({__proto__:null,getFontFamilyForCanvas:f,DEFAULT_FONT_SIZE:"11px"}),w={cssContent:".resources-dividers{position:absolute;left:0;right:0;top:0;z-index:-100;bottom:0}.resources-event-dividers{position:absolute;left:0;right:0;height:100%;top:0;z-index:300;pointer-events:none}.resources-dividers-label-bar{position:absolute;top:0;left:0;right:0;background-clip:padding-box;height:20px;z-index:200;pointer-events:none;overflow:hidden}.resources-divider{position:absolute;width:1px;top:0;bottom:0;background-color:var(--divider-line)}.resources-event-divider{position:absolute;width:1px;top:0;bottom:0;z-index:300}.resources-divider-label{position:absolute;top:4px;right:3px;font-size:80%;white-space:nowrap;pointer-events:none}.timeline-grid-header{height:20px;pointer-events:none}"};const y=new Map;class b{element;dividersElementInternal;gridHeaderElement;eventDividersElement;dividersLabelBarElementInternal;constructor(){this.element=document.createElement("div"),o.ThemeSupport.instance().appendStyle(this.element,w),this.dividersElementInternal=this.element.createChild("div","resources-dividers"),this.gridHeaderElement=document.createElement("div"),this.gridHeaderElement.classList.add("timeline-grid-header"),this.eventDividersElement=this.gridHeaderElement.createChild("div","resources-event-dividers"),this.dividersLabelBarElementInternal=this.gridHeaderElement.createChild("div","resources-dividers-label-bar"),this.element.appendChild(this.gridHeaderElement)}static calculateGridOffsets(e,t){const i=e.computePosition(e.maximumBoundary());let s=i/64,r=e.boundarySpan()/s;const n=i/e.boundarySpan(),o=Math.ceil(Math.log(r)/Math.LN10);r=Math.pow(10,o),r*n>=320&&(r/=5),r*n>=128&&(r/=2);const a=Math.ceil((e.minimumBoundary()-e.zeroTime())/r)*r+e.zeroTime();let l=e.maximumBoundary();l+=64/n,s=Math.ceil((l-a)/r),r||(s=0);const h=[];for(let i=0;i<s;++i){const s=a+r*i;e.computePosition(s)<(t||0)||h.push({position:Math.floor(e.computePosition(s)),time:s})}return{offsets:h,precision:Math.max(0,-Math.floor(Math.log(1.01*r)/Math.LN10))}}static drawCanvasGrid(e,t){e.save(),e.scale(window.devicePixelRatio,window.devicePixelRatio);const i=Math.floor(e.canvas.height/window.devicePixelRatio);e.strokeStyle=getComputedStyle(document.body).getPropertyValue("--divider-line"),e.lineWidth=1,e.translate(.5,.5),e.beginPath();for(const s of t.offsets)e.moveTo(s.position,0),e.lineTo(s.position,i);e.stroke(),e.restore()}static drawCanvasHeaders(e,t,i,s,r,n){e.save(),e.scale(window.devicePixelRatio,window.devicePixelRatio);const a=Math.ceil(e.canvas.width/window.devicePixelRatio);e.beginPath(),e.fillStyle=o.ThemeSupport.instance().getComputedValue("--color-background-opacity-50"),e.fillRect(0,0,a,r),e.fillStyle=o.ThemeSupport.instance().getComputedValue("--color-text-primary"),e.textBaseline="hanging",e.font=`11px ${f()}`;for(const r of t.offsets){const t=i(r.time),o=e.measureText(t).width,a=r.position-o-4;(!n||n<a)&&e.fillText(t,a,s)}e.restore()}get dividersElement(){return this.dividersElementInternal}get dividersLabelBarElement(){return this.dividersLabelBarElementInternal}removeDividers(){this.dividersElementInternal.removeChildren(),this.dividersLabelBarElementInternal.removeChildren()}updateDividers(e,t){const i=b.calculateGridOffsets(e,t),s=i.offsets,r=i.precision,n=this.dividersElementInternal.clientWidth;let o=this.dividersElementInternal.firstChild,a=this.dividersLabelBarElementInternal.firstChild;for(let t=0;t<s.length;++t){if(!o){o=document.createElement("div"),o.className="resources-divider",this.dividersElementInternal.appendChild(o),a=document.createElement("div"),a.className="resources-divider";const e=document.createElement("div");e.className="resources-divider-label",y.set(a,e),a.appendChild(e),this.dividersLabelBarElementInternal.appendChild(a)}const i=s[t].time,l=s[t].position;if(a){const t=y.get(a);t&&(t.textContent=e.formatValue(i,r))}const h=100*l/n;o.style.left=h+"%",a&&(a.style.left=h+"%"),o=o.nextSibling,a&&(a=a.nextSibling)}for(;o;){const e=o.nextSibling;if(this.dividersElementInternal.removeChild(o),!e)break;o=e}for(;a;){const e=a.nextSibling;if(this.dividersLabelBarElementInternal.removeChild(a),!e)break;a=e}return!0}addEventDivider(e){this.eventDividersElement.appendChild(e)}addEventDividers(e){this.gridHeaderElement.removeChild(this.eventDividersElement);for(const t of e)this.eventDividersElement.appendChild(t);this.gridHeaderElement.appendChild(this.eventDividersElement)}removeEventDividers(){this.eventDividersElement.removeChildren()}hideEventDividers(){this.eventDividersElement.classList.add("hidden")}showEventDividers(){this.eventDividersElement.classList.remove("hidden")}hideDividers(){this.dividersElementInternal.classList.add("hidden")}showDividers(){this.dividersElementInternal.classList.remove("hidden")}setScrollTop(e){this.dividersLabelBarElementInternal.style.top=e+"px",this.eventDividersElement.style.top=e+"px"}}var T=Object.freeze({__proto__:null,TimelineGrid:b}),E={cssContent:'.flame-chart-main-pane{overflow:hidden;--selected-group-background:hsl(215deg 85% 98%);--selected-group-border:hsl(216deg 68% 54%)}:host-context(.-theme-with-dark-background) .flame-chart-main-pane{--selected-group-background:hsl(215deg 85% 15%);--selected-group-border:hsl(216deg 68% 46%)}.flame-chart-marker-highlight-element{position:absolute;top:1px;height:18px;width:6px;margin:0 -3px;content:"";display:block}.flame-chart-canvas:focus-visible{border-top:1px solid var(--legacy-accent-color);border-bottom:1px solid var(--legacy-accent-color)}.flame-chart-highlight-element{position:absolute;pointer-events:none;background-color:var(--color-background-hover-overlay)}.flame-chart-selected-element{position:absolute;pointer-events:none;outline:2px solid var(--color-accent-red);background-color:var(--color-background-hover-overlay)}.chart-cursor-element{position:absolute;top:0;bottom:0;z-index:100;width:2px;background-color:var(--color-selection-highlight-border);pointer-events:none}.flame-chart-entry-info:not(:empty){z-index:2000;position:absolute;background-color:var(--color-background);pointer-events:none;padding:4px 8px;white-space:nowrap;max-width:80%;box-shadow:var(--drop-shadow)}.flame-chart-entry-info table tr td:empty{padding:0}.flame-chart-entry-info table tr td:not(:empty){padding:0 5px;white-space:nowrap}.flame-chart-entry-info table tr td:first-child{font-weight:bold}.flame-chart-entry-info table tr td span{margin-right:5px}'};const S={flameChart:"Flame Chart",sHovered:"{PH1} hovered",sSelected:"{PH1} selected",sExpanded:"{PH1} expanded",sCollapsed:"{PH1} collapsed"},x=t.i18n.registerUIStrings("ui/legacy/components/perf_ui/FlameChart.ts",S),L=t.i18n.getLocalizedString.bind(void 0,x);class C extends(e.ObjectWrapper.eventMixin(r.Widget.VBox)){groupExpansionSetting;groupExpansionState;flameChartDelegate;chartViewport;dataProvider;candyStripeCanvas;viewportElement;canvas;entryInfo;markerHighlighElement;highlightElement;selectedElement;rulerEnabled;barHeight;textBaseline;textPadding;headerLeftPadding;arrowSide;expansionArrowIndent;headerLabelXPadding;headerLabelYPadding;highlightedMarkerIndex;highlightedEntryIndex;selectedEntryIndex;rawTimelineDataLength;markerPositions;lastMouseOffsetX;selectedGroup;keyboardFocusedGroup;offsetWidth;offsetHeight;dragStartX;dragStartY;lastMouseOffsetY;minimumBoundaryInternal;maxDragOffset;timelineLevels;visibleLevelOffsets;visibleLevels;groupOffsets;rawTimelineData;forceDecorationCache;entryColorsCache;visibleLevelHeights;totalTime;#e;constructor(e,t,i){super(!0),this.#e=`11px ${f()}`,this.registerRequiredCSS(E),this.contentElement.classList.add("flame-chart-main-pane"),this.groupExpansionSetting=i,this.groupExpansionState=i&&i.get()||{},this.flameChartDelegate=t,this.chartViewport=new W(this),this.chartViewport.show(this.contentElement),this.dataProvider=e,this.candyStripeCanvas=document.createElement("canvas"),this.createCandyStripePattern(),this.viewportElement=this.chartViewport.viewportElement,this.canvas=this.viewportElement.createChild("canvas","fill"),this.canvas.tabIndex=0,r.ARIAUtils.setLabel(this.canvas,L(S.flameChart)),r.ARIAUtils.markAsTree(this.canvas),this.setDefaultFocusedElement(this.canvas),this.canvas.classList.add("flame-chart-canvas"),this.canvas.addEventListener("mousemove",this.onMouseMove.bind(this),!1),this.canvas.addEventListener("mouseout",this.onMouseOut.bind(this),!1),this.canvas.addEventListener("click",this.onClick.bind(this),!1),this.canvas.addEventListener("keydown",this.onKeyDown.bind(this),!1),this.entryInfo=this.viewportElement.createChild("div","flame-chart-entry-info"),this.markerHighlighElement=this.viewportElement.createChild("div","flame-chart-marker-highlight-element"),this.highlightElement=this.viewportElement.createChild("div","flame-chart-highlight-element"),this.selectedElement=this.viewportElement.createChild("div","flame-chart-selected-element"),this.canvas.addEventListener("focus",(()=>{this.dispatchEventToListeners(R.CanvasFocused)}),!1),r.UIUtils.installDragHandle(this.viewportElement,this.startDragging.bind(this),this.dragging.bind(this),this.endDragging.bind(this),null),this.rulerEnabled=!0,this.barHeight=17,this.textBaseline=5,this.textPadding=5,this.chartViewport.setWindowTimes(e.minimumBoundary(),e.minimumBoundary()+e.totalTime()),this.headerLeftPadding=6,this.arrowSide=8,this.expansionArrowIndent=this.headerLeftPadding+this.arrowSide/2,this.headerLabelXPadding=3,this.headerLabelYPadding=2,this.highlightedMarkerIndex=-1,this.highlightedEntryIndex=-1,this.selectedEntryIndex=-1,this.rawTimelineDataLength=0,this.markerPositions=new Map,this.lastMouseOffsetX=0,this.selectedGroup=-1,this.keyboardFocusedGroup=-1,o.ThemeSupport.instance().addEventListener(o.ThemeChangeEvent.eventName,(()=>{this.scheduleUpdate()}))}willHide(){this.hideHighlight()}setBarHeight(e){this.barHeight=e}setTextBaseline(e){this.textBaseline=e}setTextPadding(e){this.textPadding=e}enableRuler(e){this.rulerEnabled=e}alwaysShowVerticalScroll(){this.chartViewport.alwaysShowVerticalScroll()}disableRangeSelection(){this.chartViewport.disableRangeSelection()}highlightEntry(e){this.highlightedEntryIndex!==e&&this.dataProvider.entryColor(e)&&(this.highlightedEntryIndex=e,this.updateElementPosition(this.highlightElement,this.highlightedEntryIndex),this.dispatchEventToListeners(R.EntryHighlighted,e))}hideHighlight(){this.entryInfo.removeChildren(),this.highlightedEntryIndex=-1,this.updateElementPosition(this.highlightElement,this.highlightedEntryIndex),this.dispatchEventToListeners(R.EntryHighlighted,-1)}createCandyStripePattern(){const e=17;this.candyStripeCanvas.width=e,this.candyStripeCanvas.height=e;const t=this.candyStripeCanvas.getContext("2d");if(t){t.translate(8.5,8.5),t.rotate(.25*Math.PI),t.translate(-8.5,-8.5),t.fillStyle="rgba(255, 0, 0, 0.8)";for(let e=-17;e<34;e+=3)t.fillRect(e,-17,1,51)}}resetCanvas(){const e=window.devicePixelRatio,t=Math.round(this.offsetWidth*e),i=Math.round(this.offsetHeight*e);this.canvas.width=t,this.canvas.height=i,this.canvas.style.width=t/e+"px",this.canvas.style.height=i/e+"px"}windowChanged(e,t,i){this.flameChartDelegate.windowChanged(e,t,i)}updateRangeSelection(e,t){this.flameChartDelegate.updateRangeSelection(e,t)}setSize(e,t){this.offsetWidth=e,this.offsetHeight=t}startDragging(e){return this.hideHighlight(),this.maxDragOffset=0,this.dragStartX=e.pageX,this.dragStartY=e.pageY,!0}dragging(e){const t=e.pageX-this.dragStartX,i=e.pageY-this.dragStartY;this.maxDragOffset=Math.max(this.maxDragOffset,Math.sqrt(t*t+i*i))}endDragging(e){this.updateHighlight()}timelineData(){if(!this.dataProvider)return null;const e=this.dataProvider.timelineData();return(e!==this.rawTimelineData||e&&e.entryStartTimes.length!==this.rawTimelineDataLength)&&this.processTimelineData(e),this.rawTimelineData||null}revealEntry(e){const t=this.timelineData();if(!t)return;const i=this.chartViewport.windowLeftTime(),s=this.chartViewport.windowRightTime(),r=t.entryStartTimes[e],n=t.entryTotalTimes[e],o=r+n;let a=Math.min(n,s-i);const l=t.entryLevels[e];this.chartViewport.setScrollOffset(this.levelToOffset(l),this.levelHeight(l));const h=(s-i)/this.offsetWidth;if(a=Math.max(a,30*h),i>o){const e=i-o+a;this.windowChanged(i-e,s-e,!0)}else if(s<r){const e=r-s+a;this.windowChanged(i+e,s+e,!0)}}setWindowTimes(e,t,i){this.chartViewport.setWindowTimes(e,t,i),this.updateHighlight()}onMouseMove(e){const t=e;if(this.lastMouseOffsetX=t.offsetX,this.lastMouseOffsetY=t.offsetY,this.enabled()&&!this.chartViewport.isDragging())return this.coordinatesToGroupIndex(t.offsetX,t.offsetY,!0)>=0?(this.hideHighlight(),void(this.viewportElement.style.cursor="pointer")):void this.updateHighlight()}updateHighlight(){const e=this.coordinatesToEntryIndex(this.lastMouseOffsetX,this.lastMouseOffsetY);if(-1!==e)this.chartViewport.isDragging()||(this.updatePopover(e),this.viewportElement.style.cursor=this.dataProvider.canJumpToEntry(e)?"pointer":"default",this.highlightEntry(e));else{this.hideHighlight();const e=this.coordinatesToGroupIndex(this.lastMouseOffsetX,this.lastMouseOffsetY,!1);e>=0&&this.rawTimelineData&&this.rawTimelineData.groups&&this.rawTimelineData.groups[e].selectable?this.viewportElement.style.cursor="pointer":this.viewportElement.style.cursor="default"}}onMouseOut(){this.lastMouseOffsetX=-1,this.lastMouseOffsetY=-1,this.hideHighlight()}updatePopover(e){if(e===this.highlightedEntryIndex)return void this.updatePopoverOffset();this.entryInfo.removeChildren();const t=this.dataProvider.prepareHighlightedEntryInfo(e);t&&(this.entryInfo.appendChild(t),this.updatePopoverOffset())}updatePopoverOffset(){const e=this.lastMouseOffsetX,t=this.lastMouseOffsetY,s=this.entryInfo.parentElement?this.entryInfo.parentElement.clientWidth:0,r=this.entryInfo.parentElement?this.entryInfo.parentElement.clientHeight:0,n=this.entryInfo.clientWidth,o=this.entryInfo.clientHeight;let a,l;for(let h=0;h<4;++h){const d=2&h?-10-n:10,c=1&h?-6-o:6;if(a=i.NumberUtilities.clamp(e+d,0,s-n),l=i.NumberUtilities.clamp(t+c,0,r-o),a>=e||e>=a+n||l>=t||t>=l+o)break}this.entryInfo.style.left=a+"px",this.entryInfo.style.top=l+"px"}onClick(e){const t=e;this.focus();if(this.maxDragOffset>5)return;this.selectGroup(this.coordinatesToGroupIndex(t.offsetX,t.offsetY,!1)),this.toggleGroupExpand(this.coordinatesToGroupIndex(t.offsetX,t.offsetY,!0));const i=this.timelineData();if(t.shiftKey&&-1!==this.highlightedEntryIndex&&i){const e=i.entryStartTimes[this.highlightedEntryIndex],t=e+i.entryTotalTimes[this.highlightedEntryIndex];this.chartViewport.setRangeSelection(e,t)}else this.chartViewport.onClick(t),this.dispatchEventToListeners(R.EntryInvoked,this.highlightedEntryIndex)}selectGroup(e){if(e<0||this.selectedGroup===e)return;if(!this.rawTimelineData)return;const t=this.rawTimelineData.groups;if(!t)return;this.keyboardFocusedGroup=e,this.scrollGroupIntoView(e);const i=t[e].name;t[e].selectable?(this.selectedGroup=e,this.flameChartDelegate.updateSelectedGroup(this,t[e]),this.resetCanvas(),this.draw(),r.ARIAUtils.alert(L(S.sSelected,{PH1:i}))):(this.deselectAllGroups(),r.ARIAUtils.alert(L(S.sHovered,{PH1:i})))}deselectAllGroups(){this.selectedGroup=-1,this.flameChartDelegate.updateSelectedGroup(this,null),this.resetCanvas(),this.draw()}deselectAllEntries(){this.selectedEntryIndex=-1,this.resetCanvas(),this.draw()}isGroupFocused(e){return e===this.selectedGroup||e===this.keyboardFocusedGroup}scrollGroupIntoView(e){if(e<0)return;if(!this.rawTimelineData)return;const t=this.rawTimelineData.groups,i=this.groupOffsets;if(!i||!t)return;const s=i[e];let r=i[e+1];e===t.length-1&&(r+=t[e].style.padding);const n=0===e?0:s,o=Math.min(r-n,this.chartViewport.chartHeight());this.chartViewport.setScrollOffset(n,o)}toggleGroupExpand(e){e<0||!this.isGroupCollapsible(e)||this.rawTimelineData&&this.rawTimelineData.groups&&this.expandGroup(e,!this.rawTimelineData.groups[e].expanded)}expandGroup(e,t=!0,i=!1){if(e<0||!this.isGroupCollapsible(e))return;if(!this.rawTimelineData)return;const s=this.rawTimelineData.groups;if(!s)return;const n=s[e];if(n.expanded=t,this.groupExpansionState[n.name]=n.expanded,this.groupExpansionSetting&&this.groupExpansionSetting.set(this.groupExpansionState),this.updateLevelPositions(),this.updateHighlight(),!n.expanded){const t=this.timelineData();if(t){const i=t.entryLevels[this.selectedEntryIndex];this.selectedEntryIndex>=0&&i>=n.startLevel&&(e>=s.length-1||s[e+1].startLevel>i)&&(this.selectedEntryIndex=-1)}}if(this.updateHeight(),this.resetCanvas(),this.draw(),this.scrollGroupIntoView(e),!i){const t=s[e].name,i=n.expanded?L(S.sExpanded,{PH1:t}):L(S.sCollapsed,{PH1:t});r.ARIAUtils.alert(i)}}onKeyDown(e){if(!r.KeyboardShortcut.KeyboardShortcut.hasNoModifiers(e)||!this.timelineData())return;!this.handleSelectionNavigation(e)&&this.rawTimelineData&&this.rawTimelineData.groups&&this.handleKeyboardGroupNavigation(e)}bindCanvasEvent(e,t){this.canvas.addEventListener(e,t)}handleKeyboardGroupNavigation(e){const t=e;let i=!1,s=!1;"ArrowUp"===t.code?i=this.selectPreviousGroup():"ArrowDown"===t.code?i=this.selectNextGroup():"ArrowLeft"===t.code?this.keyboardFocusedGroup>=0&&(this.expandGroup(this.keyboardFocusedGroup,!1),i=!0):"ArrowRight"===t.code?this.keyboardFocusedGroup>=0&&(this.expandGroup(this.keyboardFocusedGroup,!0),this.selectFirstChild(),i=!0):"Enter"===t.key&&(s=this.selectFirstEntryInCurrentGroup(),i=s),i&&!s&&this.deselectAllEntries(),i&&t.consume(!0)}selectFirstEntryInCurrentGroup(){if(!this.rawTimelineData)return!1;const e=this.rawTimelineData.groups;if(this.keyboardFocusedGroup<0||!e)return!1;const t=e[this.keyboardFocusedGroup].startLevel;if(t<0)return!1;if(this.keyboardFocusedGroup<e.length-1&&e[this.keyboardFocusedGroup+1].startLevel===t)return!1;if(!this.timelineLevels)return!1;const i=this.timelineLevels[t][0];return this.expandGroup(this.keyboardFocusedGroup,!0),this.setSelectedEntry(i),!0}selectPreviousGroup(){if(this.keyboardFocusedGroup<=0)return!1;const e=this.getGroupIndexToSelect(-1);return this.selectGroup(e),!0}selectNextGroup(){if(!this.rawTimelineData||!this.rawTimelineData.groups)return!1;if(this.keyboardFocusedGroup>=this.rawTimelineData.groups.length-1)return!1;const e=this.getGroupIndexToSelect(1);return this.selectGroup(e),!0}getGroupIndexToSelect(e){if(!this.rawTimelineData||!this.rawTimelineData.groups)throw new Error("No raw timeline data");const t=this.rawTimelineData.groups;let i,s,r=this.keyboardFocusedGroup;do{r+=e,i=this.rawTimelineData.groups[r].name,s=-1!==this.keyboardFocusedGroup&&t[r].style.nestingLevel>t[this.keyboardFocusedGroup].style.nestingLevel}while(r>0&&r<t.length-1&&(!i||s));return r}selectFirstChild(){if(!this.rawTimelineData||!this.rawTimelineData.groups)return;const e=this.rawTimelineData.groups;if(this.keyboardFocusedGroup<0||this.keyboardFocusedGroup>=e.length-1)return;const t=this.keyboardFocusedGroup+1;e[t].style.nestingLevel>e[this.keyboardFocusedGroup].style.nestingLevel&&this.selectGroup(t)}handleSelectionNavigation(e){if(-1===this.selectedEntryIndex)return!1;const t=this.timelineData();if(!t)return!1;function s(e,i){if(!t)throw new Error("No timeline data");const s=t.entryStartTimes[e],r=t.entryStartTimes[i],n=s+t.entryTotalTimes[e];return s<r+t.entryTotalTimes[i]&&r<n}const n=e,o=r.KeyboardShortcut.Keys;if(n.keyCode===o.Left.code||n.keyCode===o.Right.code){const s=t.entryLevels[this.selectedEntryIndex],r=this.timelineLevels?this.timelineLevels[s]:[];let a=i.ArrayUtilities.lowerBound(r,this.selectedEntryIndex,((e,t)=>e-t));return a+=n.keyCode===o.Left.code?-1:1,e.consume(!0),a>=0&&a<r.length&&this.dispatchEventToListeners(R.EntrySelected,r[a]),!0}if(n.keyCode===o.Up.code||n.keyCode===o.Down.code){let e=t.entryLevels[this.selectedEntryIndex];if(e+=n.keyCode===o.Up.code?-1:1,e<0||this.timelineLevels&&e>=this.timelineLevels.length)return this.deselectAllEntries(),n.consume(!0),!0;const r=t.entryStartTimes[this.selectedEntryIndex]+t.entryTotalTimes[this.selectedEntryIndex]/2,a=this.timelineLevels?this.timelineLevels[e]:[];let l=i.ArrayUtilities.upperBound(a,r,(function(e,i){if(!t)throw new Error("No timeline data");return e-t.entryStartTimes[i]}))-1;return!s(this.selectedEntryIndex,a[l])&&(++l,l>=a.length||!s(this.selectedEntryIndex,a[l]))?"ArrowDown"!==n.code&&(this.deselectAllEntries(),n.consume(!0),!0):(n.consume(!0),this.dispatchEventToListeners(R.EntrySelected,a[l]),!0)}return"Enter"===e.key&&(e.consume(!0),this.dispatchEventToListeners(R.EntryInvoked,this.selectedEntryIndex),!0)}coordinatesToEntryIndex(e,t){if(e<0||t<0)return-1;const s=this.timelineData();if(!s)return-1;if(t+=this.chartViewport.scrollOffset(),!this.visibleLevelOffsets)throw new Error("No visible level offsets");const r=i.ArrayUtilities.upperBound(this.visibleLevelOffsets,t,i.ArrayUtilities.DEFAULT_COMPARATOR)-1;if(r<0||this.visibleLevels&&!this.visibleLevels[r])return-1;if(t-this.visibleLevelOffsets[r]>this.levelHeight(r))return-1;for(const[t,i]of this.markerPositions)if(s.entryLevels[t]===r&&i.x<=e&&e<i.x+i.width)return t;const n=s.entryStartTimes,o=this.timelineLevels?this.timelineLevels[r]:[];if(!o||!o.length)return-1;const a=this.chartViewport.pixelToTime(e),l=Math.max(i.ArrayUtilities.upperBound(o,a,((e,t)=>e-n[t]))-1,0);function h(t){if(void 0===t)return!1;if(!s)return!1;const i=n[t],r=s.entryTotalTimes[t],o=this.chartViewport.timeToPosition(i),a=this.chartViewport.timeToPosition(i+r);return o-3<e&&e<a+3}let d=o[l];return h.call(this,d)?d:(d=o[l+1],h.call(this,d)?d:-1)}coordinatesToGroupIndex(e,t,s){if(!this.rawTimelineData||!this.rawTimelineData.groups||!this.groupOffsets)return-1;if(e<0||t<0)return-1;t+=this.chartViewport.scrollOffset();const r=this.rawTimelineData.groups||[],n=i.ArrayUtilities.upperBound(this.groupOffsets,t,i.ArrayUtilities.DEFAULT_COMPARATOR)-1;if(n<0||n>=r.length)return-1;const o=s?r[n].style.height:this.groupOffsets[n+1]-this.groupOffsets[n];if(t-this.groupOffsets[n]>=o)return-1;if(!s)return n;const a=this.canvas.getContext("2d");a.save(),a.font=this.#e;const l=this.headerLeftPadding+this.labelWidthForGroup(a,r[n]);return a.restore(),e>l?-1:n}markerIndexBeforeTime(e){const t=this.timelineData();if(!t)throw new Error("No timeline data");if(!t.markers)throw new Error("No timeline markers");return i.ArrayUtilities.lowerBound(t.markers,e,((e,t)=>e-t.startTime()))}draw(){const e=this.timelineData();if(!e)return;const t=this.offsetWidth,i=this.offsetHeight,s=this.canvas.getContext("2d");s.save();const r=window.devicePixelRatio,n=this.chartViewport.scrollOffset();s.scale(r,r),s.fillStyle="rgba(0, 0, 0, 0)",s.fillRect(0,0,t,i),s.translate(0,-n),s.font=this.#e;const{markerIndices:a,colorBuckets:l,titleIndices:h}=this.getDrawableData(s,e);s.save(),this.forEachGroupInViewport(((e,i,r,n,a)=>{this.isGroupFocused(i)&&(s.fillStyle=o.ThemeSupport.instance().getComputedValue("--selected-group-background",this.contentElement),s.fillRect(0,e,t,a-r.style.padding))})),s.restore();for(const[t,{indexes:i}]of l)this.#t(s,e,t,i),this.#i(s,e,i);this.drawMarkers(s,e,a),this.drawEventTitles(s,e,h,t),s.restore(),this.drawGroupHeaders(t,i),this.drawFlowEvents(s,t,i),this.drawMarkerLines();const d=b.calculateGridOffsets(this),c=Array.from(this.dataProvider.navStartTimes().values());let m=0;const u=e=>{if(0===c.length)return this.formatValue(e,d.precision);c.length>m+1&&e>c[m+1].startTime&&m++;const t=c[m];return t&&(e-=t.startTime-this.zeroTime()),this.formatValue(e,d.precision)};b.drawCanvasGrid(s,d),this.rulerEnabled&&b.drawCanvasHeaders(s,d,u,3,P),this.updateElementPosition(this.highlightElement,this.highlightedEntryIndex),this.updateElementPosition(this.selectedElement,this.selectedEntryIndex),this.updateMarkerHighlight()}#t(e,t,i,s){e.save(),e.beginPath();for(let i=0;i<s.length;++i){const r=s[i];this.#s(e,t,r)}e.fillStyle=i,e.fill(),e.restore()}#i(e,t,i){const{entryTotalTimes:s,entryStartTimes:r,entryLevels:o}=t;e.save();for(let a=0;a<i.length;++a){const l=i[a],h=t.entryDecorations.at(l);if(!h||h.length<1)continue;h.length>1&&D(h);const d=r[l],c=e.createPattern(this.candyStripeCanvas,"repeat");for(const i of h){const r=s[l];if("CANDY"===i.type){const s=n.Helpers.Timing.microSecondsToMilliseconds(i.startAtTime);if(r<s)continue;e.save(),e.beginPath();const o=this.timeToPositionClipped(d+s),a=this.timeToPositionClipped(d+r);this.#s(e,t,l,{startX:o,width:a-o}),c&&(e.fillStyle=c,e.fill()),e.restore()}else if("WARNING_TRIANGLE"===i.type){const i=this.timeToPositionClipped(d),s=o[l],r=this.#r(t,l),n=this.levelToOffset(s),a=this.#n(t,l),h=8;e.save(),e.beginPath(),e.rect(i,n,a,r),e.clip(),e.beginPath(),e.fillStyle="red",e.moveTo(i+a-h,n),e.lineTo(i+a,n),e.lineTo(i+a,n+h),e.fill(),e.restore()}}}e.restore()}#s(e,t,i,s){const{entryTotalTimes:r,entryStartTimes:n,entryLevels:o}=t,a=r[i];if(isNaN(a))return;const l=n[i],h=s?.startX||this.timeToPositionClipped(l),d=o[i],c=this.#r(t,i),m=this.levelToOffset(d),u=s?.width||this.#n(t,i);e.rect(h,m,u-.5,c-1)}#r(e,t){const{entryLevels:i}=e,s=i[t];return this.levelHeight(s)}#n(e,t){const{entryTotalTimes:i,entryStartTimes:s}=e,r=i[t],n=s[t],o=this.timeToPositionClipped(n),a=this.timeToPositionClipped(n+r);return Math.max(a-o,1)}getDrawableData(e,t){const s=[],n=[],{entryTotalTimes:o,entryStartTimes:a}=t,l=this.offsetHeight,h=this.chartViewport.scrollOffset(),d=this.visibleLevelOffsets?this.visibleLevelOffsets:new Uint32Array,c=2*this.textPadding+r.UIUtils.measureTextWidth(e,"…"),m=this.chartViewport.pixelToTimeOffset(c),u=Math.max(i.ArrayUtilities.upperBound(d,h,i.ArrayUtilities.DEFAULT_COMPARATOR)-1,0),g=new Map;for(let e=u;e<this.dataProvider.maxStackDepth()&&!(this.levelToOffset(e)>h+l);++e){if(!this.visibleLevels||!this.visibleLevels[e])continue;if(!this.timelineLevels)continue;const t=this.timelineLevels[e];let r=1/0;for(let e=i.ArrayUtilities.lowerBound(t,this.chartViewport.windowRightTime(),((e,t)=>e-a[t]))-1;e>=0;--e){const i=t[e],l=o[i];if(isNaN(l)){n.push(i);continue}(l>=m||this.forceDecorationCache&&this.forceDecorationCache[i])&&s.push(i);const h=a[i];if(h+l<=this.chartViewport.windowLeftTime())break;const d=this.timeToPositionClipped(h);if(!(d>=r)&&(r=d,this.entryColorsCache)){const e=this.entryColorsCache[i];let t=g.get(e);t||(t={indexes:[]},g.set(e,t)),t.indexes.push(i)}}}return{colorBuckets:g,titleIndices:s,markerIndices:n}}drawGroupHeaders(t,i){const s=this.canvas.getContext("2d"),r=this.chartViewport.scrollOffset(),n=window.devicePixelRatio;if(!this.rawTimelineData)return;const a=this.rawTimelineData.groups||[];if(!a.length)return;const l=this.groupOffsets;if(null==l)return;const h=l[l.length-1];function d(e){s.moveTo(0,e),s.lineTo(t,e)}function c(e,t,i){const r=this.arrowSide*Math.sqrt(3)/2,n=Math.round(r/2);s.save(),s.translate(e,t),s.rotate(i?Math.PI/2:0),s.moveTo(-n,-this.arrowSide/2),s.lineTo(-n,this.arrowSide/2),s.lineTo(r-n,0),s.restore()}s.save(),s.scale(n,n),s.translate(0,-r),s.font=this.#e,s.fillStyle=o.ThemeSupport.instance().getComputedValue("--color-background"),this.forEachGroupInViewport(((e,i,r)=>{const n=r.style.padding;n<5||s.fillRect(0,e-n+2,t,n-4)})),a.length&&h<r+i&&s.fillRect(0,h+2,t,r+i-h),s.strokeStyle=o.ThemeSupport.instance().getComputedValue("--color-background-elevation-1"),s.beginPath(),this.forEachGroupInViewport(((e,t,i,s)=>{s||i.style.padding<4||d(e-2.5)})),d(h+1.5),s.stroke(),this.forEachGroupInViewport(((e,i,r)=>{if(r.style.useFirstLineForOverview)return;if(!this.isGroupCollapsible(i)||r.expanded)return void(!r.style.shareHeaderLine&&this.isGroupFocused(i)&&(s.fillStyle=r.style.backgroundColor,s.fillRect(0,e,t,r.style.height)));let n=i+1;for(;n<a.length&&a[n].style.nestingLevel>r.style.nestingLevel;)n++;const o=n<a.length?a[n].startLevel:this.dataProvider.maxStackDepth();this.drawCollapsedOverviewForGroup(r,e,o)})),s.save(),this.forEachGroupInViewport(((t,i,r)=>{if(s.font=this.#e,this.isGroupCollapsible(i)&&!r.expanded||r.style.shareHeaderLine){const n=this.labelWidthForGroup(s,r)+2;if(this.isGroupFocused(i))s.fillStyle=o.ThemeSupport.instance().getComputedValue("--selected-group-background",this.contentElement);else{const t=e.Color.parse(r.style.backgroundColor);t&&(s.fillStyle=t.setAlpha(.8).asString())}s.fillRect(this.headerLeftPadding-this.headerLabelXPadding,t+this.headerLabelYPadding,n,r.style.height-2*this.headerLabelYPadding)}s.fillStyle=r.style.color,s.fillText(r.name,Math.floor(this.expansionArrowIndent*(r.style.nestingLevel+1)+this.arrowSide),t+r.style.height-this.textBaseline)})),s.restore(),s.fillStyle=o.ThemeSupport.instance().getComputedValue("--color-text-secondary"),s.beginPath(),this.forEachGroupInViewport(((e,t,i)=>{this.isGroupCollapsible(t)&&c.call(this,this.expansionArrowIndent*(i.style.nestingLevel+1),e+i.style.height-this.textBaseline-this.arrowSide/2,Boolean(i.expanded))})),s.fill(),s.strokeStyle=o.ThemeSupport.instance().getComputedValue("--color-details-hairline-light"),s.beginPath(),s.stroke(),this.forEachGroupInViewport(((e,t,i,r,n)=>{if(this.isGroupFocused(t)){const t=2,r=10;s.fillStyle=o.ThemeSupport.instance().getComputedValue("--selected-group-border",this.contentElement),s.fillRect(0,e-t,t,n-i.style.padding+2*t),s.fillRect(0,e-t,r,t),s.fillRect(0,e+n-i.style.padding,r,t)}})),s.restore()}drawMarkers(e,t,i){const{entryStartTimes:s,entryLevels:n}=t;this.markerPositions.clear(),e.textBaseline="alphabetic",e.save(),e.beginPath();let o=-1,a=-1/0;for(let t=i.length-1;t>=0;--t){const l=i[t],h=this.dataProvider.entryTitle(l);if(!h)continue;const d=s[l],c=n[l];o!==c&&(a=-1/0);const m=Math.max(this.chartViewport.timeToPosition(d),a),u=this.levelToOffset(c),g=this.levelHeight(c),p=4,f=Math.ceil(r.UIUtils.measureTextWidth(e,h))+2*p;a=m+f+1,o=c,this.markerPositions.set(l,{x:m,width:f}),e.fillStyle=this.dataProvider.entryColor(l),e.fillRect(m,u,f,g-1),e.fillStyle="white",e.fillText(h,m+p,u+g-this.textBaseline)}e.strokeStyle="rgba(0, 0, 0, 0.2)",e.stroke(),e.restore()}drawEventTitles(e,t,i,s){const n=this.chartViewport.timeToPixel(),o=this.textPadding;e.save(),e.beginPath();const{entryStartTimes:a,entryLevels:l}=t;for(let h=0;h<i.length;++h){const d=i[h],c=a[d],m=this.timeToPositionClipped(c),u=Math.min(this.#n(t,d),s),g=l[d],p=this.levelToOffset(g);let f=this.dataProvider.entryTitle(d);f&&f.length&&(e.font=this.#e,f=r.UIUtils.trimTextMiddle(e,f,u-2*o));const v=this.chartViewport.timeToPosition(c),w=this.#r(t,d);this.dataProvider.decorateEntry(d,e,f,m,p,u,w,v,n)||f&&f.length&&(e.fillStyle=this.dataProvider.textColor(d),e.fillText(f,m+o,p+w-this.textBaseline))}e.restore()}forEachGroup(e){if(!this.rawTimelineData)return;const t=this.rawTimelineData.groups||[];if(!t.length)return;const i=this.groupOffsets;if(!i)return;const s=[{nestingLevel:-1,visible:!0}];for(let r=0;r<t.length;++r){const n=i[r],o=t[r];let a=!0,l=s[s.length-1];for(;l&&l.nestingLevel>=o.style.nestingLevel;)s.pop(),a=!1,l=s[s.length-1];l=s[s.length-1];const h=!!l&&l.visible,d=h&&(!this.isGroupCollapsible(r)||o.expanded);s.push({nestingLevel:o.style.nestingLevel,visible:Boolean(d)});const c=r===t.length-1?i[r+1]+o.style.padding:i[r+1];h&&e(n,r,o,a,c-n)}}forEachGroupInViewport(e){const t=this.chartViewport.scrollOffset();this.forEachGroup(((i,s,r,n,o)=>{i-r.style.padding>t+this.offsetHeight||i+o<t||e(i,s,r,n,o)}))}labelWidthForGroup(e,t){return r.UIUtils.measureTextWidth(e,t.name)+this.expansionArrowIndent*(t.style.nestingLevel+1)+2*this.headerLabelXPadding}drawCollapsedOverviewForGroup(t,s,r){const n=new e.SegmentedRange.SegmentedRange((function(e,t){return e.data===t.data&&e.end+.4>t.end?e:null})),o=this.chartViewport.windowLeftTime(),a=this.chartViewport.windowRightTime(),l=this.canvas.getContext("2d"),h=t.style.height;if(!this.rawTimelineData)return;const d=this.rawTimelineData.entryStartTimes,c=this.rawTimelineData.entryTotalTimes,m=this.chartViewport.timeToPixel();for(let u=t.startLevel;u<r;++u){const r=this.timelineLevels?this.timelineLevels[u]:[];let g=1/0;for(let u=i.ArrayUtilities.lowerBound(r,a,((e,t)=>e-d[t]))-1;u>=0;--u){const i=r[u],a=d[i],p=this.timeToPositionClipped(a),f=a+c[i];if(isNaN(f)||p>=g)continue;if(f<=o)break;g=p;const v=this.entryColorsCache?this.entryColorsCache[i]:"",w=this.timeToPositionClipped(f);if(t.style.useDecoratorsForOverview&&this.dataProvider.forceDecoration(i)){const e=this.chartViewport.timeToPosition(a),t=this.#n(this.rawTimelineData,i);l.beginPath(),l.fillStyle=v,l.fillRect(p,s,t,h-1),this.dataProvider.decorateEntry(i,l,"",p,s,t,h,e,m)}else n.append(new e.SegmentedRange.Segment(p,w,v))}}const u=n.segments().slice().sort(((e,t)=>e.data.localeCompare(t.data)));let g;l.beginPath();for(let e=0;e<u.length;++e){const t=u[e];g!==u[e].data&&(l.fill(),l.beginPath(),g=u[e].data,l.fillStyle=g),l.rect(t.begin,s,t.end-t.begin,h)}l.fill()}drawFlowEvents(e,t,s){e.save();const r=window.devicePixelRatio,n=this.chartViewport.scrollOffset();e.scale(r,r),e.translate(0,-n),e.fillStyle="#7f5050",e.strokeStyle="#7f5050";const o=this.timelineData();if(!o)return;const a=i.ArrayUtilities.lowerBound(o.flowStartTimes,this.chartViewport.windowRightTime(),i.ArrayUtilities.DEFAULT_COMPARATOR);e.lineWidth=.5;for(let t=0;t<a;++t){if(!o.flowEndTimes[t]||o.flowEndTimes[t]<this.chartViewport.windowLeftTime())continue;const i=this.chartViewport.timeToPosition(o.flowStartTimes[t]),s=this.chartViewport.timeToPosition(o.flowEndTimes[t]),r=o.flowStartLevels[t],n=o.flowEndLevels[t],a=this.levelToOffset(r)+this.levelHeight(r)/2,l=this.levelToOffset(n)+this.levelHeight(n)/2,h=Math.min((s-i)/4,40),d=(l-a)/10,c=30,m=o.flowEndTimes[t]-o.flowStartTimes[t]<1?a:c+Math.max(0,a+d*(t%c)),u=[];u.push({x:i,y:a}),u.push({x:i+6,y:a}),u.push({x:i+h+12,y:a}),u.push({x:i+h,y:m}),u.push({x:i+2*h,y:m}),u.push({x:s-2*h,y:m}),u.push({x:s-h,y:m}),u.push({x:s-h-12,y:l}),u.push({x:s-6,y:l}),e.beginPath(),e.moveTo(u[0].x,u[0].y),e.lineTo(u[1].x,u[1].y),e.bezierCurveTo(u[2].x,u[2].y,u[3].x,u[3].y,u[4].x,u[4].y),e.lineTo(u[5].x,u[5].y),e.bezierCurveTo(u[6].x,u[6].y,u[7].x,u[7].y,u[8].x,u[8].y),e.stroke(),e.beginPath(),e.arc(i,a,2,-Math.PI/2,Math.PI/2,!1),e.fill(),e.beginPath(),e.moveTo(s,l),e.lineTo(s-6,l-3),e.lineTo(s-6,l+3),e.fill()}e.restore()}drawMarkerLines(){const e=this.timelineData();if(!e)return;const t=e.markers,i=this.markerIndexBeforeTime(this.minimumBoundary()),s=this.maximumBoundary(),r=this.chartViewport.timeToPixel(),n=this.canvas.getContext("2d");n.save();const o=window.devicePixelRatio;n.scale(o,o),n.translate(0,3);const a=P-1;for(let e=i;e<t.length;e++){const i=t[e].startTime();if(i>s)break;t[e].draw(n,this.chartViewport.timeToPosition(i),a,r)}n.restore()}updateMarkerHighlight(){const e=this.markerHighlighElement;e.parentElement&&e.remove();const t=this.highlightedMarkerIndex;if(-1===t)return;const i=this.timelineData();if(!i)return;const s=i.markers[t],n=this.timeToPositionClipped(s.startTime());r.Tooltip.Tooltip.install(e,s.title()||"");const o=e.style;o.left=n+"px",o.backgroundColor=s.color(),this.viewportElement.appendChild(e)}processTimelineData(e){if(!e)return this.timelineLevels=null,this.visibleLevelOffsets=null,this.visibleLevels=null,this.groupOffsets=null,this.rawTimelineData=null,this.forceDecorationCache=null,this.entryColorsCache=null,this.rawTimelineDataLength=0,this.selectedGroup=-1,this.keyboardFocusedGroup=-1,void this.flameChartDelegate.updateSelectedGroup(this,null);this.rawTimelineData=e,this.rawTimelineDataLength=e.entryStartTimes.length,this.forceDecorationCache=new Int8Array(this.rawTimelineDataLength),this.entryColorsCache=new Array(this.rawTimelineDataLength);for(let e=0;e<this.rawTimelineDataLength;++e)this.forceDecorationCache[e]=this.dataProvider.forceDecoration(e)?1:0,this.entryColorsCache[e]=this.dataProvider.entryColor(e);const t=new Uint32Array(this.dataProvider.maxStackDepth()+1);for(let i=0;i<e.entryLevels.length;++i)++t[e.entryLevels[i]];const i=new Array(t.length);for(let e=0;e<i.length;++e)i[e]=new Uint32Array(t[e]),t[e]=0;for(let s=0;s<e.entryLevels.length;++s){const r=e.entryLevels[s];i[r][t[r]++]=s}this.timelineLevels=i;const s=this.rawTimelineData.groups||[];for(let e=0;e<s.length;++e){const t=this.groupExpansionState[s[e].name];void 0!==t&&(s[e].expanded=t)}this.updateLevelPositions(),this.updateHeight(),this.selectedGroup=e.selectedGroup?s.indexOf(e.selectedGroup):-1,this.keyboardFocusedGroup=this.selectedGroup,this.flameChartDelegate.updateSelectedGroup(this,e.selectedGroup)}updateLevelPositions(){const e=this.dataProvider.maxStackDepth(),t=this.rawTimelineData&&this.rawTimelineData.groups||[];this.visibleLevelOffsets=new Uint32Array(e+1),this.visibleLevelHeights=new Uint32Array(e),this.visibleLevels=new Uint16Array(e),this.groupOffsets=new Uint32Array(t.length+1);let i=-1,s=this.rulerEnabled?P+2:2,r=!0;const n=[{nestingLevel:-1,visible:!0}],o=Math.max(e,t.length?t[t.length-1].startLevel+1:0);let a;for(a=0;a<o;++a){let o,l=!0;for(;i<t.length-1&&a===t[i+1].startLevel;){++i,o=t[i].style;let e=!0,a=n[n.length-1];for(;a&&a.nestingLevel>=o.nestingLevel;)n.pop(),e=!1,a=n[n.length-1];const h=!(i>=0&&this.isGroupCollapsible(i))||t[i].expanded;a=n[n.length-1],l=!!a&&a.visible,r=Boolean(h)&&l,n.push({nestingLevel:o.nestingLevel,visible:r}),l&&(s+=e?0:o.padding),this.groupOffsets[i]=s,l&&!o.shareHeaderLine&&(s+=o.height)}if(a>=e)continue;const h=i>=0&&a===t[i].startLevel,d=l&&(r||h&&t[i].style.useFirstLineForOverview);let c;if(i>=0){const e=t[i],s=e.style;c=h&&!s.shareHeaderLine||s.collapsible&&!e.expanded?s.height:s.itemsHeight||this.barHeight}else c=this.barHeight;this.visibleLevels[a]=d?1:0,this.visibleLevelOffsets[a]=s,this.visibleLevelHeights[a]=c,(d||l&&o&&o.shareHeaderLine&&h)&&(s+=this.visibleLevelHeights[a])}i>=0&&(this.groupOffsets[i+1]=s),this.visibleLevelOffsets[a]=s}isGroupCollapsible(e){if(!this.rawTimelineData)return;const t=this.rawTimelineData.groups||[],i=t[e].style;if(!i.shareHeaderLine||!i.collapsible)return Boolean(i.collapsible);const s=e+1>=t.length;if(!s&&t[e+1].style.nestingLevel>i.nestingLevel)return!0;return(s?this.dataProvider.maxStackDepth():t[e+1].startLevel)!==t[e].startLevel+1||i.height!==i.itemsHeight}setSelectedEntry(e){this.selectedEntryIndex!==e&&(-1!==e&&this.chartViewport.hideRangeSelection(),this.selectedEntryIndex=e,this.revealEntry(e),this.updateElementPosition(this.selectedElement,this.selectedEntryIndex))}updateElementPosition(e,t){if(e.classList.add("hidden"),-1===t)return;const i=this.timelineData();if(!i)return;const s=i.entryStartTimes[t],r=i.entryTotalTimes[t];let n=0,o=0,a=!0;if(Number.isNaN(r)){const e=this.markerPositions.get(t);e?(n=e.x,o=e.width):a=!1}else n=this.chartViewport.timeToPosition(s),o=r*this.chartViewport.timeToPixel();if(n+o<=0||n>=this.offsetWidth)return;const l=n+o/2;o=Math.max(o,2),n=l-o/2;const h=i.entryLevels[t],d=this.levelToOffset(h)-this.chartViewport.scrollOffset(),c=this.levelHeight(h),m=e.style;m.left=n+"px",m.top=d+"px",m.width=o+"px",m.height=c-1+"px",e.classList.toggle("hidden",!a),this.viewportElement.appendChild(e)}timeToPositionClipped(e){return i.NumberUtilities.clamp(this.chartViewport.timeToPosition(e),0,this.offsetWidth)}levelToOffset(e){if(!this.visibleLevelOffsets)throw new Error("No visible level offsets");return this.visibleLevelOffsets[e]}levelHeight(e){if(!this.visibleLevelHeights)throw new Error("No visible level heights");return this.visibleLevelHeights[e]}updateBoundaries(){this.totalTime=this.dataProvider.totalTime(),this.minimumBoundaryInternal=this.dataProvider.minimumBoundary(),this.chartViewport.setBoundaries(this.minimumBoundaryInternal,this.totalTime)}updateHeight(){const e=this.levelToOffset(this.dataProvider.maxStackDepth())+2;this.chartViewport.setContentHeight(e)}onResize(){this.scheduleUpdate()}update(){this.timelineData()&&(this.resetCanvas(),this.updateHeight(),this.updateBoundaries(),this.draw(),this.chartViewport.isDragging()||this.updateHighlight())}reset(){this.chartViewport.reset(),this.rawTimelineData=null,this.rawTimelineDataLength=0,this.highlightedMarkerIndex=-1,this.highlightedEntryIndex=-1,this.selectedEntryIndex=-1,this.chartViewport.scheduleUpdate()}scheduleUpdate(){this.chartViewport.scheduleUpdate()}enabled(){return 0!==this.rawTimelineDataLength}computePosition(e){return this.chartViewport.timeToPosition(e)}formatValue(e,t){return this.dataProvider.formatValue(e-this.zeroTime(),t)}maximumBoundary(){return this.chartViewport.windowRightTime()}minimumBoundary(){return this.chartViewport.windowLeftTime()}zeroTime(){return this.dataProvider.minimumBoundary()}boundarySpan(){return this.maximumBoundary()-this.minimumBoundary()}}const P=15,k={CANDY:1,WARNING_TRIANGLE:2};function D(e){e.sort(((e,t)=>k[e.type]-k[t.type]))}class I{entryLevels;entryTotalTimes;entryStartTimes;entryDecorations;groups;markers;flowStartTimes;flowStartLevels;flowEndTimes;flowEndLevels;selectedGroup;constructor(e,t,i,s,r=[]){this.entryLevels=e,this.entryTotalTimes=t,this.entryStartTimes=i,this.entryDecorations=r,this.groups=s||[],this.markers=[],this.flowStartTimes=[],this.flowStartLevels=[],this.flowEndTimes=[],this.flowEndLevels=[],this.selectedGroup=null}static create(e){return new I(e.entryLevels,e.entryTotalTimes,e.entryStartTimes,e.groups,e.entryDecorations||[])}static createEmpty(){return new I([],[],[],[])}}var R;!function(e){e.CanvasFocused="CanvasFocused",e.EntryInvoked="EntryInvoked",e.EntrySelected="EntrySelected",e.EntryHighlighted="EntryHighlighted"}(R||(R={}));var M=Object.freeze({__proto__:null,FlameChartDelegate:class{windowChanged(e,t,i){}updateRangeSelection(e,t){}updateSelectedGroup(e,t){}},FlameChart:C,HeaderHeight:P,MinimalTimeWindowMs:.5,sortDecorationsForRenderingOrder:D,FlameChartTimelineData:I,get Events(){return R}});const z=s.RenderCoordinator.RenderCoordinator.instance();class W extends r.Widget.VBox{delegate;viewportElement;alwaysShowVerticalScrollInternal;rangeSelectionEnabled;vScrollElement;vScrollContent;selectionOverlay;selectedTimeSpanLabel;cursorElement;isDraggingInternal;totalHeight;offsetHeight;scrollTop;rangeSelectionStart;rangeSelectionEnd;dragStartPointX;dragStartPointY;dragStartScrollTop;visibleLeftTime;visibleRightTime;offsetWidth;targetLeftTime;targetRightTime;selectionOffsetShiftX;selectionOffsetShiftY;selectionStartX;lastMouseOffsetX;minimumBoundary;totalTime;cancelWindowTimesAnimation;constructor(e){super(),this.registerRequiredCSS(g),this.delegate=e,this.viewportElement=this.contentElement.createChild("div","fill"),this.viewportElement.addEventListener("mousemove",this.updateCursorPosition.bind(this),!1),this.viewportElement.addEventListener("mouseout",this.onMouseOut.bind(this),!1),this.viewportElement.addEventListener("wheel",this.onMouseWheel.bind(this),!1),this.viewportElement.addEventListener("keydown",this.onChartKeyDown.bind(this),!1),this.viewportElement.addEventListener("keyup",this.onChartKeyUp.bind(this),!1),r.UIUtils.installDragHandle(this.viewportElement,this.startDragging.bind(this),this.dragging.bind(this),this.endDragging.bind(this),"-webkit-grabbing",null),r.UIUtils.installDragHandle(this.viewportElement,this.startRangeSelection.bind(this),this.rangeSelectionDragging.bind(this),this.endRangeSelection.bind(this),"text",null),this.alwaysShowVerticalScrollInternal=!1,this.rangeSelectionEnabled=!0,this.vScrollElement=this.contentElement.createChild("div","chart-viewport-v-scroll"),this.vScrollContent=this.vScrollElement.createChild("div"),this.vScrollElement.addEventListener("scroll",this.onScroll.bind(this),!1),this.selectionOverlay=this.contentElement.createChild("div","chart-viewport-selection-overlay hidden"),this.selectedTimeSpanLabel=this.selectionOverlay.createChild("div","time-span"),this.cursorElement=this.contentElement.createChild("div","chart-cursor-element hidden"),this.reset(),this.rangeSelectionStart=null,this.rangeSelectionEnd=null}alwaysShowVerticalScroll(){this.alwaysShowVerticalScrollInternal=!0,this.vScrollElement.classList.add("always-show-scrollbar")}disableRangeSelection(){this.rangeSelectionEnabled=!1,this.rangeSelectionStart=null,this.rangeSelectionEnd=null,this.updateRangeSelectionOverlay()}isDragging(){return this.isDraggingInternal}elementsToRestoreScrollPositionsFor(){return[this.vScrollElement]}updateScrollBar(){const e=this.alwaysShowVerticalScrollInternal||this.totalHeight>this.offsetHeight;this.vScrollElement.classList.contains("hidden")===e&&(this.vScrollElement.classList.toggle("hidden",!e),this.updateContentElementSize())}onResize(){this.updateScrollBar(),this.updateContentElementSize(),this.scheduleUpdate()}reset(){this.vScrollElement.scrollTop=0,this.scrollTop=0,this.rangeSelectionStart=null,this.rangeSelectionEnd=null,this.isDraggingInternal=!1,this.dragStartPointX=0,this.dragStartPointY=0,this.dragStartScrollTop=0,this.visibleLeftTime=0,this.visibleRightTime=0,this.offsetWidth=0,this.offsetHeight=0,this.totalHeight=0,this.targetLeftTime=0,this.targetRightTime=0,this.updateContentElementSize()}updateContentElementSize(){let e=this.vScrollElement.offsetLeft;e||(e=this.contentElement.offsetWidth),this.offsetWidth=e,this.offsetHeight=this.contentElement.offsetHeight,this.delegate.setSize(this.offsetWidth,this.offsetHeight)}setContentHeight(e){this.totalHeight=e,this.vScrollContent.style.height=e+"px",this.updateScrollBar(),this.updateContentElementSize(),this.scrollTop+this.offsetHeight<=e||(this.scrollTop=Math.max(0,e-this.offsetHeight),this.vScrollElement.scrollTop=this.scrollTop)}setScrollOffset(e,t){t=t||0,this.vScrollElement.scrollTop>e?this.vScrollElement.scrollTop=e:this.vScrollElement.scrollTop<e-this.offsetHeight+t&&(this.vScrollElement.scrollTop=e-this.offsetHeight+t)}scrollOffset(){return this.vScrollElement.scrollTop}chartHeight(){return this.offsetHeight}setBoundaries(e,t){this.minimumBoundary=e,this.totalTime=t}onMouseWheel(t){const i=t,s=i.shiftKey!==("zoom"===e.Settings.Settings.instance().moduleSetting("flamechartMouseWheelAction").get()),r=!s&&(i.deltaY||53===Math.abs(i.deltaX)),n=s&&Math.abs(i.deltaX)>Math.abs(i.deltaY);if(r)this.vScrollElement.scrollTop+=(i.deltaY||i.deltaX)/53*this.offsetHeight/8;else if(n)this.handlePanGesture(i.deltaX,!0);else{const e=1/53;this.handleZoomGesture(Math.pow(1.2,(i.deltaY||i.deltaX)*e)-1)}t.consume(!0)}startDragging(e){return!e.shiftKey&&(this.isDraggingInternal=!0,this.dragStartPointX=e.pageX,this.dragStartPointY=e.pageY,this.dragStartScrollTop=this.vScrollElement.scrollTop,this.viewportElement.style.cursor="",!0)}dragging(e){const t=this.dragStartPointX-e.pageX;this.dragStartPointX=e.pageX,this.handlePanGesture(t);const i=this.dragStartPointY-e.pageY;this.vScrollElement.scrollTop=this.dragStartScrollTop+i}endDragging(){this.isDraggingInternal=!1}startRangeSelection(e){if(!e.shiftKey||!this.rangeSelectionEnabled)return!1;this.isDraggingInternal=!0,this.selectionOffsetShiftX=e.offsetX-e.pageX,this.selectionOffsetShiftY=e.offsetY-e.pageY,this.selectionStartX=e.offsetX;const t=this.selectionOverlay.style;return t.left=this.selectionStartX+"px",t.width="1px",this.selectedTimeSpanLabel.textContent="",this.selectionOverlay.classList.remove("hidden"),!0}endRangeSelection(){this.isDraggingInternal=!1,this.selectionStartX=null}hideRangeSelection(){this.selectionOverlay.classList.add("hidden"),this.rangeSelectionStart=null,this.rangeSelectionEnd=null}setRangeSelection(e,t){this.rangeSelectionEnabled&&(this.rangeSelectionStart=Math.min(e,t),this.rangeSelectionEnd=Math.max(e,t),this.updateRangeSelectionOverlay(),this.delegate.updateRangeSelection(this.rangeSelectionStart,this.rangeSelectionEnd))}onClick(e){const t=e,i=this.pixelToTime(t.offsetX);null!==this.rangeSelectionStart&&null!==this.rangeSelectionEnd&&i>=this.rangeSelectionStart&&i<=this.rangeSelectionEnd||this.hideRangeSelection()}rangeSelectionDragging(e){const t=i.NumberUtilities.clamp(e.pageX+this.selectionOffsetShiftX,0,this.offsetWidth),s=this.pixelToTime(this.selectionStartX||0),r=this.pixelToTime(t);this.setRangeSelection(s,r)}updateRangeSelectionOverlay(){const e=this.rangeSelectionStart||0,s=this.rangeSelectionEnd||0,r=100,n=i.NumberUtilities.clamp(this.timeToPosition(e),-100,this.offsetWidth+r),o=i.NumberUtilities.clamp(this.timeToPosition(s),-100,this.offsetWidth+r),a=this.selectionOverlay.style;a.left=n+"px",a.width=o-n+"px";const l=s-e;this.selectedTimeSpanLabel.textContent=t.TimeUtilities.preciseMillisToString(l,2)}onScroll(){this.scrollTop=this.vScrollElement.scrollTop,this.scheduleUpdate()}onMouseOut(){this.lastMouseOffsetX=-1,this.showCursor(!1)}updateCursorPosition(e){const t=e;this.showCursor(t.shiftKey),this.cursorElement.style.left=t.offsetX+"px",this.lastMouseOffsetX=t.offsetX}pixelToTime(e){return this.pixelToTimeOffset(e)+this.visibleLeftTime}pixelToTimeOffset(e){return e*(this.visibleRightTime-this.visibleLeftTime)/this.offsetWidth}timeToPosition(e){return Math.floor((e-this.visibleLeftTime)/(this.visibleRightTime-this.visibleLeftTime)*this.offsetWidth)}timeToPixel(){return this.offsetWidth/(this.visibleRightTime-this.visibleLeftTime)}showCursor(e){this.cursorElement.classList.toggle("hidden",!e||this.isDraggingInternal)}onChartKeyDown(e){const t=e;this.showCursor(t.shiftKey),this.handleZoomPanKeys(e)}onChartKeyUp(e){const t=e;this.showCursor(t.shiftKey)}handleZoomPanKeys(e){if(!r.KeyboardShortcut.KeyboardShortcut.hasNoModifiers(e))return;const t=e,i=t.shiftKey?.8:.3,s=t.shiftKey?320:160;switch(t.code){case"KeyA":this.handlePanGesture(-s,!0);break;case"KeyD":this.handlePanGesture(s,!0);break;case"KeyW":this.handleZoomGesture(-i);break;case"KeyS":this.handleZoomGesture(i);break;default:return}e.consume(!0)}handleZoomGesture(e){const t={left:this.targetLeftTime,right:this.targetRightTime},i=this.pixelToTime(this.lastMouseOffsetX);t.left+=(t.left-i)*e,t.right+=(t.right-i)*e,this.requestWindowTimes(t,!0)}handlePanGesture(e,t){const s={left:this.targetLeftTime,right:this.targetRightTime},r=i.NumberUtilities.clamp(this.pixelToTimeOffset(e),this.minimumBoundary-s.left,this.totalTime+this.minimumBoundary-s.right);s.left+=r,s.right+=r,this.requestWindowTimes(s,Boolean(t))}requestWindowTimes(e,t){const i=this.minimumBoundary+this.totalTime;e.left<this.minimumBoundary?(e.right=Math.min(e.right+this.minimumBoundary-e.left,i),e.left=this.minimumBoundary):e.right>i&&(e.left=Math.max(e.left-e.right+i,this.minimumBoundary),e.right=i),e.right-e.left<.5||this.delegate.windowChanged(e.left,e.right,t)}scheduleUpdate(){this.cancelWindowTimesAnimation||z.write((()=>this.update()))}update(){this.updateRangeSelectionOverlay(),this.delegate.update()}setWindowTimes(e,t,i){if(e!==this.targetLeftTime||t!==this.targetRightTime){if(!i||0===this.visibleLeftTime||this.visibleRightTime===1/0||0===e&&t===1/0||e===1/0&&t===1/0)return this.targetLeftTime=e,this.targetRightTime=t,this.visibleLeftTime=e,this.visibleRightTime=t,void this.scheduleUpdate();this.cancelWindowTimesAnimation&&(this.cancelWindowTimesAnimation(),this.visibleLeftTime=this.targetLeftTime,this.visibleRightTime=this.targetRightTime),this.targetLeftTime=e,this.targetRightTime=t,this.cancelWindowTimesAnimation=r.UIUtils.animateFunction(this.element.window(),function(e,t){this.visibleLeftTime=e,this.visibleRightTime=t,this.update()}.bind(this),[{from:this.visibleLeftTime,to:e},{from:this.visibleRightTime,to:t}],100,(()=>{this.cancelWindowTimesAnimation=null}))}}windowLeftTime(){return this.visibleLeftTime}windowRightTime(){return this.visibleRightTime}}var A=Object.freeze({__proto__:null,ChartViewport:W}),H={cssContent:".film-strip-view{overflow-x:auto;overflow-y:hidden;align-content:flex-start;min-height:81px}.film-strip-view .frame .time{font-size:10px;margin-top:2px}.film-strip-view.time-based .frame .time{display:none}.film-strip-view .label{margin:auto;font-size:18px;color:var(--color-text-secondary)}.film-strip-view .frame{display:flex;flex-direction:column;align-items:center;padding:4px;flex:none;cursor:pointer}.film-strip-view .frame .thumbnail{min-width:24px;display:flex;flex-direction:row;align-items:center;pointer-events:none;margin:4px 0 2px;border:2px solid transparent}.film-strip-view .frame:hover .thumbnail,\n.film-strip-view .frame:focus .thumbnail{border-color:var(--color-selection-highlight-border)}.film-strip-view .frame .thumbnail img{height:auto;width:auto;max-width:80px;max-height:50px;pointer-events:none;box-shadow:0 0 3px var(--box-shadow-outline-color);flex:0 0 auto}.film-strip-view .frame:hover .thumbnail img,\n.film-strip-view .frame:focus .thumbnail img{box-shadow:none}"};const O={doubleclickToZoomImageClickTo:"Doubleclick to zoom image. Click to view preceding requests.",screenshotForSSelectToView:"Screenshot for {PH1} - select to view preceding requests.",screenshot:"Screenshot",previousFrame:"Previous frame",nextFrame:"Next frame"},G=t.i18n.registerUIStrings("ui/legacy/components/perf_ui/FilmStripView.ts",O),F=t.i18n.getLocalizedString.bind(void 0,G);class B extends(e.ObjectWrapper.eventMixin(r.Widget.HBox)){statusLabel;zeroTime;spanTime;model;mode;constructor(){super(!0),this.registerRequiredCSS(H),this.contentElement.classList.add("film-strip-view"),this.statusLabel=this.contentElement.createChild("div","label"),this.reset(),this.setMode(V.TimeBased)}static setImageData(e,t){t&&(e.src="data:image/jpg;base64,"+t)}setMode(e){this.mode=e,this.contentElement.classList.toggle("time-based",e===V.TimeBased),this.update()}setModel(e,t,i){this.model=e,this.zeroTime=t,this.spanTime=i;e.frames().length?this.update():this.reset()}createFrameElement(e){const i=e.timestamp,s=t.TimeUtilities.millisToString(i-this.zeroTime),n=document.createElement("div");n.classList.add("frame"),r.Tooltip.Tooltip.install(n,F(O.doubleclickToZoomImageClickTo)),n.createChild("div","time").textContent=s,n.tabIndex=0,n.setAttribute("aria-label",F(O.screenshotForSSelectToView,{PH1:s})),r.ARIAUtils.markAsButton(n);const o=n.createChild("div","thumbnail").createChild("img");return o.alt=F(O.screenshot),n.addEventListener("mousedown",this.onMouseEvent.bind(this,U.FrameSelected,i),!1),n.addEventListener("mouseenter",this.onMouseEvent.bind(this,U.FrameEnter,i),!1),n.addEventListener("mouseout",this.onMouseEvent.bind(this,U.FrameExit,i),!1),n.addEventListener("dblclick",this.onDoubleClick.bind(this,e),!1),n.addEventListener("focusin",this.onMouseEvent.bind(this,U.FrameEnter,i),!1),n.addEventListener("focusout",this.onMouseEvent.bind(this,U.FrameExit,i),!1),n.addEventListener("keydown",(e=>{"Enter"!==e.code&&"Space"!==e.code||this.onMouseEvent(U.FrameSelected,i)})),e.imageDataPromise().then(B.setImageData.bind(null,o)).then((function(){return n}))}frameByTime(e){const t=this.model.frames(),s=Math.max(i.ArrayUtilities.upperBound(t,e,(function(e,t){return e-t.timestamp}))-1,0);return t[s]}update(){if(!this.model)return;const e=this.model.frames();if(!e.length)return;if(this.mode===V.FrameBased)return void Promise.all(e.map(this.createFrameElement.bind(this))).then(s.bind(this));const t=this.contentElement.clientWidth,i=this.spanTime/t;function s(e){this.contentElement.removeChildren();for(let t=0;t<e.length;++t)this.contentElement.appendChild(e[t])}this.createFrameElement(e[0]).then(function(e){const n=Math.ceil(r.UIUtils.measurePreferredSize(e,this.contentElement).width);if(!n)return;const o=[];for(let e=n;e<t;e+=n){const t=e*i+this.zeroTime;o.push(this.createFrameElement(this.frameByTime(t)).then(a))}function a(e){return e.style.width=n+"px",e}Promise.all(o).then(s.bind(this))}.bind(this))}onResize(){this.mode!==V.FrameBased&&this.update()}onMouseEvent(e,t){this.dispatchEventToListeners(e,t)}onDoubleClick(e){new N(e,this.zeroTime)}reset(){this.zeroTime=0,this.contentElement.removeChildren(),this.contentElement.appendChild(this.statusLabel)}setStatusText(e){this.statusLabel.textContent=e}}var U;!function(e){e.FrameSelected="FrameSelected",e.FrameEnter="FrameEnter",e.FrameExit="FrameExit"}(U||(U={}));const V={TimeBased:"TimeBased",FrameBased:"FrameBased"};class N{fragment;widget;frames;index;zeroTime;dialog;constructor(e,t){const i=r.UIUtils.createTextButton("◀",this.onPrevFrame.bind(this));r.Tooltip.Tooltip.install(i,F(O.previousFrame));const s=r.UIUtils.createTextButton("▶",this.onNextFrame.bind(this));r.Tooltip.Tooltip.install(s,F(O.nextFrame)),this.fragment=r.Fragment.Fragment.build`
      <x-widget flex=none margin=12px>
        <x-hbox overflow=auto border='1px solid #ddd'>
          <img $='image' style="max-height: 80vh; max-width: 80vw;"></img>
        </x-hbox>
        <x-hbox x-center justify-content=center margin-top=10px>
          ${i}
          <x-hbox $='time' margin=8px></x-hbox>
          ${s}
        </x-hbox>
      </x-widget>
    `,this.widget=this.fragment.element(),this.widget.tabIndex=0,this.widget.addEventListener("keydown",this.keyDown.bind(this),!1),this.frames=e.model().frames(),this.index=e.index,this.zeroTime=t||e.model().zeroTime(),this.dialog=null,this.render()}resize(){this.dialog||(this.dialog=new r.Dialog.Dialog,this.dialog.contentElement.appendChild(this.widget),this.dialog.setDefaultFocusedElement(this.widget),this.dialog.show()),this.dialog.setSizeBehavior("MeasureContent")}keyDown(e){const t=e;switch(t.key){case"ArrowLeft":a.Platform.isMac()&&t.metaKey?this.onFirstFrame():this.onPrevFrame();break;case"ArrowRight":a.Platform.isMac()&&t.metaKey?this.onLastFrame():this.onNextFrame();break;case"Home":this.onFirstFrame();break;case"End":this.onLastFrame()}}onPrevFrame(){this.index>0&&--this.index,this.render()}onNextFrame(){this.index<this.frames.length-1&&++this.index,this.render()}onFirstFrame(){this.index=0,this.render()}onLastFrame(){this.index=this.frames.length-1,this.render()}render(){const e=this.frames[this.index];return this.fragment.$("time").textContent=t.TimeUtilities.millisToString(e.timestamp-this.zeroTime),e.imageDataPromise().then((e=>{const t=this.fragment.$("image");return B.setImageData(t,e)})).then(this.resize.bind(this))}}var _=Object.freeze({__proto__:null,FilmStripView:B,get Events(){return U},Modes:V,Dialog:N});let X;class ${static instance(e={forceNew:null}){const{forceNew:t}=e;return X&&!t||(X=new $),X}handleAction(e,t){for(const e of l.TargetManager.TargetManager.instance().models(l.HeapProfilerModel.HeapProfilerModel))e.collectGarbage();return!0}}var j=Object.freeze({__proto__:null,GCActionDelegate:$});let Y,K;class q{helper;constructor(){this.helper=new J(c.SourceFrame.DecoratorType.PERFORMANCE)}static instance(e={forceNew:null}){const{forceNew:t}=e;return Y&&!t||(Y=new q),Y}reset(){this.helper.reset()}appendLegacyCPUProfile(e){const t=e.target(),i=[e.profileHead],s=(e.profileEndTime-e.profileStartTime)/e.totalHitCount;for(;i.length;){const e=i.pop().children;for(let r=0;r<e.length;++r){const n=e[r];if(i.push(n),n.url&&n.positionTicks)for(let e=0;e<n.positionTicks.length;++e){const i=n.positionTicks[e],r=i.line,o=i.ticks*s;this.helper.addLineData(t,n.url,r,o)}}}}appendCPUProfile(e){if(!e.lines)return this.appendLegacyCPUProfile(e),void this.helper.scheduleUpdate();const t=e.target();if(e.samples){for(let i=1;i<e.samples.length;++i){const s=e.lines[i];if(!s)continue;const r=e.nodeByIndex(i);if(!r)continue;const n=Number(r.scriptId)||r.url;if(!n)continue;const o=e.timestamps[i]-e.timestamps[i-1];this.helper.addLineData(t,n,s,o)}this.helper.scheduleUpdate()}}}class Z{helper;constructor(){this.helper=new J(c.SourceFrame.DecoratorType.MEMORY)}static instance(e={forceNew:null}){const{forceNew:t}=e;return K&&!t||(K=new Z),K}reset(){this.helper.reset()}appendHeapProfile(e,t){const i=this.helper;!function e(s){if(s.children.forEach(e),!s.selfSize)return;const r=Number(s.callFrame.scriptId)||s.callFrame.url;if(!r)return;const n=s.callFrame.lineNumber+1;i.addLineData(t,r,n,s.selfSize)}(e.head),i.scheduleUpdate()}}class J{type;locationPool;updateTimer;lineData;constructor(e){this.type=e,this.locationPool=new h.LiveLocation.LiveLocationPool,this.updateTimer=null,this.reset()}reset(){this.lineData=new Map,this.scheduleUpdate()}addLineData(e,t,i,s){let r=this.lineData.get(e);r||(r=new Map,this.lineData.set(e,r));let n=r.get(t);n||(n=new Map,r.set(t,n)),n.set(i,(n.get(i)||0)+s)}scheduleUpdate(){this.updateTimer||(this.updateTimer=window.setTimeout((()=>{this.updateTimer=null,this.doUpdate()}),0))}async doUpdate(){this.locationPool.disposeAll();const e=new Map,t=[];for(const[i,s]of this.lineData){const r=i?i.model(l.DebuggerModel.DebuggerModel):null;for(const[i,n]of s){const s=d.Workspace.WorkspaceImpl.instance();if(r){const s=h.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance();for(const o of n){const n=o[0]-1,a=o[1],l="string"==typeof i?r.createRawLocationByURL(i,n,0):r.createRawLocationByScriptId(String(i),n,0);l&&t.push(s.rawLocationToUILocation(l).then((t=>{if(t){let i=e.get(t.uiSourceCode);i||(i=new Map,e.set(t.uiSourceCode,i)),i.set(t.lineNumber+1,a)}})))}}else if("string"==typeof i){const t=s.uiSourceCodeForURL(i);t&&e.set(t,n)}}await Promise.all(t);for(const[t,i]of e)t.setDecorationData(this.type,i)}for(const t of d.Workspace.WorkspaceImpl.instance().uiSourceCodes())e.has(t)||t.setDecorationData(this.type,void 0)}}var Q=Object.freeze({__proto__:null,Performance:q,Memory:Z,Helper:J});let ee;class te{running;sessionId;loadEventCallback;setting;constructor(){this.running=!1,this.sessionId=0,this.loadEventCallback=()=>{},this.setting=e.Settings.Settings.instance().moduleSetting("memoryLiveHeapProfile"),this.setting.addChangeListener((e=>e.data?this.startProfiling():this.stopProfiling())),this.setting.get()&&this.startProfiling()}static instance(e={forceNew:null}){const{forceNew:t}=e;return ee&&!t||(ee=new te),ee}async run(){}modelAdded(e){e.startSampling(1e4)}modelRemoved(e){}async startProfiling(){if(this.running)return;this.running=!0;const e=this.sessionId;l.TargetManager.TargetManager.instance().observeModels(l.HeapProfilerModel.HeapProfilerModel,this),l.TargetManager.TargetManager.instance().addModelListener(l.ResourceTreeModel.ResourceTreeModel,l.ResourceTreeModel.Events.Load,this.loadEventFired,this);do{const t=l.TargetManager.TargetManager.instance().models(l.HeapProfilerModel.HeapProfilerModel),i=await Promise.all(t.map((e=>e.getSamplingProfile())));if(e!==this.sessionId)break;Z.instance().reset();for(let e=0;e<i.length;++e){const s=i[e];s&&Z.instance().appendHeapProfile(s,t[e].target())}await Promise.race([new Promise((e=>window.setTimeout(e,a.InspectorFrontendHost.isUnderTest()?10:5e3))),new Promise((e=>{this.loadEventCallback=e}))])}while(e===this.sessionId);l.TargetManager.TargetManager.instance().unobserveModels(l.HeapProfilerModel.HeapProfilerModel,this),l.TargetManager.TargetManager.instance().removeModelListener(l.ResourceTreeModel.ResourceTreeModel,l.ResourceTreeModel.Events.Load,this.loadEventFired,this);for(const e of l.TargetManager.TargetManager.instance().models(l.HeapProfilerModel.HeapProfilerModel))e.stopSampling();Z.instance().reset()}stopProfiling(){this.running&&(this.running=!1,this.sessionId++)}loadEventFired(){this.loadEventCallback()}}var ie=Object.freeze({__proto__:null,LiveHeapProfile:te});const se={lowest:"Lowest",low:"Low",medium:"Medium",high:"High",highest:"Highest"},re=t.i18n.registerUIStrings("ui/legacy/components/perf_ui/NetworkPriorities.ts",se),ne=t.i18n.getLocalizedString.bind(void 0,re);const oe=new Map;let ae;function le(){if(ae)return ae;const e=new Map;return e.set("VeryLow",ne(se.lowest)),e.set("Low",ne(se.low)),e.set("Medium",ne(se.medium)),e.set("High",ne(se.high)),e.set("VeryHigh",ne(se.highest)),ae=e,e}const he=new Map;var de=Object.freeze({__proto__:null,uiLabelForNetworkPriority:function(e){return le().get(e)||""},uiLabelToNetworkPriority:function(e){return 0===oe.size&&le().forEach(((e,t)=>oe.set(e,t))),oe.get(e)||""},priorityUILabelMap:le,networkPriorityWeight:function(e){return 0===he.size&&(he.set("VeryLow",1),he.set("Low",2),he.set("Medium",3),he.set("High",4),he.set("VeryHigh",5)),he.get(e)||0}}),ce={cssContent:".overview-grid-window-selector{position:absolute;top:0;bottom:0;background-color:var(--color-selection-highlight);z-index:250;pointer-events:none}.overview-grid-window-resizer{position:absolute;top:-1px;height:20px;width:6px;margin-left:-3px;background-color:rgb(153 153 153);border:1px solid #fff;z-index:500}.overview-grid-window-resizer:focus-visible{background-color:var(--legacy-active-control-bg-color)}.overview-grid-cursor-area{position:absolute;left:0;right:0;top:20px;bottom:0;z-index:500;cursor:text}.overview-grid-cursor-position{position:absolute;top:0;bottom:0;width:2px;background-color:var(--color-selection-highlight-border);z-index:500;pointer-events:none;visibility:hidden;overflow:hidden}.window-curtain-left,\n.window-curtain-right{background-color:var(--color-background-hover-overlay);position:absolute;top:0;height:100%;z-index:300;pointer-events:none;border:1px none var(--color-background-hover-overlay)}.window-curtain-left{left:0;border-right-style:solid}.window-curtain-right{right:0;border-left-style:solid}@media (forced-colors: active){.overview-grid-cursor-position{forced-color-adjust:none;background-color:Highlight}.window-curtain-left,\n  .window-curtain-right{background-color:transparent;border-color:ButtonText}.overview-grid-window-resizer{background-color:ButtonText}.overview-grid-window-resizer:hover,\n  .overview-grid-window-resizer:active,\n  .overview-grid-window-resizer:focus-visible{forced-color-adjust:none;background-color:Highlight}}"};const me={overviewGridWindow:"Overview grid window",leftResizer:"Left Resizer",rightResizer:"Right Resizer"},ue=t.i18n.registerUIStrings("ui/legacy/components/perf_ui/OverviewGrid.ts",me),ge=t.i18n.getLocalizedString.bind(void 0,ue);class pe{element;grid;window;constructor(e,t){this.element=document.createElement("div"),this.element.id=e+"-overview-container",this.grid=new b,this.grid.element.id=e+"-overview-grid",this.grid.setScrollTop(0),this.element.appendChild(this.grid.element),this.window=new fe(this.element,this.grid.dividersLabelBarElement,t)}clientWidth(){return this.element.clientWidth}updateDividers(e){this.grid.updateDividers(e)}addEventDividers(e){this.grid.addEventDividers(e)}removeEventDividers(){this.grid.removeEventDividers()}reset(){this.window.reset()}windowLeft(){return this.window.windowLeft||0}windowRight(){return this.window.windowRight||0}setWindow(e,t){this.window.setWindow(e,t)}addEventListener(e,t,i){return this.window.addEventListener(e,t,i)}setClickHandler(e){this.window.setClickHandler(e)}zoom(e,t){this.window.zoom(e,t)}setResizeEnabled(e){this.window.setEnabled(e)}}class fe extends e.ObjectWrapper.ObjectWrapper{parentElement;calculator;leftResizeElement;rightResizeElement;leftCurtainElement;rightCurtainElement;overviewWindowSelector;offsetLeft;dragStartPoint;dragStartLeft;dragStartRight;windowLeft;windowRight;enabled;clickHandler;resizerParentOffsetLeft;constructor(e,t,i){super(),this.parentElement=e,r.ARIAUtils.markAsGroup(this.parentElement),this.calculator=i,r.ARIAUtils.setLabel(this.parentElement,ge(me.overviewGridWindow)),r.UIUtils.installDragHandle(this.parentElement,this.startWindowSelectorDragging.bind(this),this.windowSelectorDragging.bind(this),this.endWindowSelectorDragging.bind(this),"text",null),t&&r.UIUtils.installDragHandle(t,this.startWindowDragging.bind(this),this.windowDragging.bind(this),null,"-webkit-grabbing","-webkit-grab"),this.parentElement.addEventListener("wheel",this.onMouseWheel.bind(this),!0),this.parentElement.addEventListener("dblclick",this.resizeWindowMaximum.bind(this),!0),o.ThemeSupport.instance().appendStyle(this.parentElement,ce),this.leftResizeElement=e.createChild("div","overview-grid-window-resizer"),r.UIUtils.installDragHandle(this.leftResizeElement,this.resizerElementStartDragging.bind(this),this.leftResizeElementDragging.bind(this),null,"ew-resize"),this.rightResizeElement=e.createChild("div","overview-grid-window-resizer"),r.UIUtils.installDragHandle(this.rightResizeElement,this.resizerElementStartDragging.bind(this),this.rightResizeElementDragging.bind(this),null,"ew-resize"),r.ARIAUtils.setLabel(this.leftResizeElement,ge(me.leftResizer)),r.ARIAUtils.markAsSlider(this.leftResizeElement);this.leftResizeElement.addEventListener("keydown",(e=>this.handleKeyboardResizing(e,!1))),r.ARIAUtils.setLabel(this.rightResizeElement,ge(me.rightResizer)),r.ARIAUtils.markAsSlider(this.rightResizeElement);this.rightResizeElement.addEventListener("keydown",(e=>this.handleKeyboardResizing(e,!0))),this.rightResizeElement.addEventListener("focus",this.onRightResizeElementFocused.bind(this)),this.leftCurtainElement=e.createChild("div","window-curtain-left"),this.rightCurtainElement=e.createChild("div","window-curtain-right"),this.reset()}onRightResizeElementFocused(){this.parentElement.scrollLeft=0}reset(){this.windowLeft=0,this.windowRight=1,this.setEnabled(!0),this.updateCurtains()}setEnabled(e){this.enabled=e,this.rightResizeElement.tabIndex=e?0:-1,this.leftResizeElement.tabIndex=e?0:-1}setClickHandler(e){this.clickHandler=e}resizerElementStartDragging(e){const t=e,i=e.target;return!!this.enabled&&(this.resizerParentOffsetLeft=t.pageX-t.offsetX-i.offsetLeft,e.stopPropagation(),!0)}leftResizeElementDragging(e){const t=e;this.resizeWindowLeft(t.pageX-(this.resizerParentOffsetLeft||0)),e.preventDefault()}rightResizeElementDragging(e){const t=e;this.resizeWindowRight(t.pageX-(this.resizerParentOffsetLeft||0)),e.preventDefault()}handleKeyboardResizing(e,t){const i=e,s=e.target;let r=!1;if("ArrowLeft"===i.key||"ArrowRight"===i.key){"ArrowRight"===i.key&&(r=!0);const n=this.getNewResizerPosition(s.offsetLeft,r,i.ctrlKey);t?this.resizeWindowRight(n):this.resizeWindowLeft(n),e.consume(!0)}}getNewResizerPosition(e,t,i){let s,r=i?10:2;r=t?r:-Math.abs(r);return s=e+3.5+r,t&&s<10?s=10:!t&&s>this.parentElement.clientWidth-10&&(s=this.parentElement.clientWidth-10),s}startWindowSelectorDragging(e){if(!this.enabled)return!1;const t=e;this.offsetLeft=this.parentElement.getBoundingClientRect().left;const i=t.x-this.offsetLeft;return this.overviewWindowSelector=new we(this.parentElement,i),!0}windowSelectorDragging(e){if(!this.overviewWindowSelector)return;const t=e;this.overviewWindowSelector.updatePosition(t.x-this.offsetLeft),e.preventDefault()}endWindowSelectorDragging(e){if(!this.overviewWindowSelector)return;const t=e,i=this.overviewWindowSelector.close(t.x-this.offsetLeft);delete this.overviewWindowSelector;if(i.end-i.start<3){if(this.clickHandler&&this.clickHandler.call(null,e))return;const t=i.end;i.start=Math.max(0,t-7),i.end=Math.min(this.parentElement.clientWidth,t+7)}else i.end-i.start<14&&(this.parentElement.clientWidth-i.end>14?i.end=i.start+14:i.start=i.end-14);this.setWindowPosition(i.start,i.end)}startWindowDragging(e){const t=e;return this.dragStartPoint=t.pageX,this.dragStartLeft=this.windowLeft||0,this.dragStartRight=this.windowRight||0,e.stopPropagation(),!0}windowDragging(e){const t=e;t.preventDefault();let i=(t.pageX-this.dragStartPoint)/this.parentElement.clientWidth;this.dragStartLeft+i<0&&(i=-this.dragStartLeft),this.dragStartRight+i>1&&(i=1-this.dragStartRight),this.setWindow(this.dragStartLeft+i,this.dragStartRight+i)}resizeWindowLeft(e){e<10?e=0:e>this.rightResizeElement.offsetLeft-4&&(e=this.rightResizeElement.offsetLeft-4),this.setWindowPosition(e,null)}resizeWindowRight(e){e>this.parentElement.clientWidth-10?e=this.parentElement.clientWidth:e<this.leftResizeElement.offsetLeft+14&&(e=this.leftResizeElement.offsetLeft+14),this.setWindowPosition(null,e)}resizeWindowMaximum(){this.setWindowPosition(0,this.parentElement.clientWidth)}getRawSliderValue(e){if(!this.calculator)throw new Error("No calculator to calculate boundaries");const t=this.calculator.minimumBoundary(),i=this.calculator.maximumBoundary()-t;return e?t+i*(this.windowLeft||0):t+i*(this.windowRight||0)}updateResizeElementPositionValue(e,t){const i=e.toFixed(2),s=t.toFixed(2);r.ARIAUtils.setAriaValueNow(this.leftResizeElement,i),r.ARIAUtils.setAriaValueNow(this.rightResizeElement,s);const n=Number(s)-.5,o=Number(i)+.5;r.ARIAUtils.setAriaValueMinMax(this.leftResizeElement,"0",n.toString()),r.ARIAUtils.setAriaValueMinMax(this.rightResizeElement,o.toString(),"100")}updateResizeElementPositionLabels(){if(!this.calculator)return;const e=this.calculator.formatValue(this.getRawSliderValue(!0)),t=this.calculator.formatValue(this.getRawSliderValue(!1));r.ARIAUtils.setAriaValueText(this.leftResizeElement,String(e)),r.ARIAUtils.setAriaValueText(this.rightResizeElement,String(t))}updateResizeElementPercentageLabels(e,t){r.ARIAUtils.setAriaValueText(this.leftResizeElement,e),r.ARIAUtils.setAriaValueText(this.rightResizeElement,t)}calculateWindowPosition(){return{rawStartValue:Number(this.getRawSliderValue(!0)),rawEndValue:Number(this.getRawSliderValue(!1))}}setWindow(e,t){this.windowLeft=e,this.windowRight=t,this.updateCurtains(),this.calculator&&this.dispatchEventToListeners(ve.WindowChangedWithPosition,this.calculateWindowPosition()),this.dispatchEventToListeners(ve.WindowChanged)}updateCurtains(){const e=this.windowLeft||0,t=this.windowRight||0;let i=e,s=t;const r=s-i;if(0!==this.parentElement.clientWidth){const n=r*this.parentElement.clientWidth,o=7;if(n<o){const a=o/n;i=(t+e-r*a)/2,s=(t+e+r*a)/2}}const n=100*i,o=100*s,a=100-100*s,l=n+"%",h=o+"%";this.leftResizeElement.style.left=l,this.rightResizeElement.style.left=h,this.leftCurtainElement.style.width=l,this.rightCurtainElement.style.width=a+"%",this.updateResizeElementPositionValue(n,o),this.calculator?this.updateResizeElementPositionLabels():this.updateResizeElementPercentageLabels(l,h)}setWindowPosition(e,t){const i=this.parentElement.clientWidth,s="number"==typeof e?e/i:this.windowLeft,r="number"==typeof t?t/i:this.windowRight;this.setWindow(s||0,r||0)}onMouseWheel(e){const t=e;if(this.enabled){if(t.deltaY){const e=1.1,i=1/53,s=t.offsetX/this.parentElement.clientWidth;this.zoom(Math.pow(e,t.deltaY*i),s)}if(t.deltaX){let e=Math.round(.3*t.deltaX);const i=this.leftResizeElement.offsetLeft+3.5,s=this.rightResizeElement.offsetLeft+3.5;i-e<0&&(e=i),s-e>this.parentElement.clientWidth&&(e=s-this.parentElement.clientWidth),this.setWindowPosition(i-e,s-e),t.preventDefault()}}}zoom(e,t){let s=this.windowLeft||0,r=this.windowRight||0;const n=r-s;let o=e*n;o>1&&(o=1,e=o/n),s=t+(s-t)*e,s=i.NumberUtilities.clamp(s,0,1-o),r=t+(r-t)*e,r=i.NumberUtilities.clamp(r,o,1),this.setWindow(s,r)}}var ve;!function(e){e.WindowChanged="WindowChanged",e.WindowChangedWithPosition="WindowChangedWithPosition"}(ve||(ve={}));class we{startPosition;width;windowSelector;constructor(e,t){this.startPosition=t,this.width=e.offsetWidth,this.windowSelector=document.createElement("div"),this.windowSelector.className="overview-grid-window-selector",this.windowSelector.style.left=this.startPosition+"px",this.windowSelector.style.right=this.width-this.startPosition+"px",e.appendChild(this.windowSelector)}close(e){return e=Math.max(0,Math.min(e,this.width)),this.windowSelector.remove(),this.startPosition<e?{start:this.startPosition,end:e}:{start:e,end:this.startPosition}}updatePosition(e){(e=Math.max(0,Math.min(e,this.width)))<this.startPosition?(this.windowSelector.style.left=e+"px",this.windowSelector.style.right=this.width-this.startPosition+"px"):(this.windowSelector.style.left=this.startPosition+"px",this.windowSelector.style.right=this.width-e+"px")}}var ye=Object.freeze({__proto__:null,OverviewGrid:pe,MinSelectableSize:14,WindowScrollSpeedFactor:.3,ResizerOffset:3.5,OffsetFromWindowEnds:10,Window:fe,get Events(){return ve},WindowSelector:we});const be=new CSSStyleSheet;be.replaceSync(".root{align-items:center;display:flex;min-width:fit-content;white-space:nowrap}.chart-root{position:relative;overflow:hidden}.pie-chart-foreground{position:absolute;width:100%;height:100%;z-index:10;top:0;display:flex;pointer-events:none}.pie-chart-total{margin:auto;padding:2px 5px;pointer-events:auto}:focus{outline-width:0}.pie-chart-total.selected{font-weight:bold}.chart-root .slice.selected{stroke:var(--legacy-selection-bg-color);stroke-opacity:1;stroke-width:0.04;stroke-linecap:round;stroke-linejoin:round}.pie-chart-legend{margin-left:30px}.pie-chart-legend-row{margin:5px 2px 5px auto;padding-right:25px}.pie-chart-legend-row.selected{font-weight:bold}.pie-chart-legend-row:focus-visible{box-shadow:0 0 0 2px var(--legacy-selection-bg-color)!important}.pie-chart-swatch{display:inline-block;width:11px;height:11px;margin:0 6px;top:1px;position:relative;border:1px solid rgb(100 100 100/20%)}.pie-chart-swatch.pie-chart-empty-swatch{border:none}.pie-chart-name{display:inline-block}.pie-chart-size{display:inline-block;text-align:right;width:70px}@media (forced-colors: active){.pie-chart-swatch{forced-color-adjust:none;border-color:ButtonText}.pie-chart-total{forced-color-adjust:none;background-color:canvas}}\n/*# sourceURL=pieChart.css */\n");const{render:Te,html:Ee,svg:Se}=u,xe={total:"Total"},Le=t.i18n.registerUIStrings("ui/legacy/components/perf_ui/PieChart.ts",xe),Ce=t.i18n.getLocalizedString.bind(void 0,Le);class Pe extends HTMLElement{static litTagName=u.literal`devtools-perf-piechart`;shadow=this.attachShadow({mode:"open"});chartName="";size=0;formatter=e=>String(e);showLegend=!1;total=0;slices=[];totalSelected=!0;sliceSelected=-1;innerR=.618;lastAngle=-Math.PI/2;connectedCallback(){this.shadow.adoptedStyleSheets=[be]}set data(e){this.chartName=e.chartName,this.size=e.size,this.formatter=e.formatter,this.showLegend=e.showLegend,this.total=e.total,this.slices=e.slices,this.render()}render(){this.lastAngle=-Math.PI/2;const e=Ee` <div class="root" role="group" @keydown="${this.onKeyDown}" aria-label="${this.chartName}"> <div class="chart-root" style="width: ${this.size}px; height: ${this.size}px;"> ${Se` <svg> <g transform="scale(${this.size/2}) translate(1, 1) scale(0.99, 0.99)"> <circle r="1" stroke="hsl(0, 0%, 80%)" fill="transparent" stroke-width="${1/this.size}"></circle> <circle r="${this.innerR}" stroke="hsl(0, 0%, 80%)" fill="transparent" stroke-width="${1/this.size}"></circle> ${this.slices.map(((e,t)=>{const i=this.sliceSelected===t,s=i&&!this.showLegend?"0":"-1";return Se`<path class="slice ${i?"selected":""}" @click="${this.onSliceClicked(t)}" tabIndex="${s}" fill="${e.color}" d="${this.getPathStringForSlice(e)}" aria-label="${e.title}" id="${i?"selectedSlice":""}"></path>`}))} <use href="#selectedSlice"/> </g> </svg> `} <div class="pie-chart-foreground"> <div class="pie-chart-total ${this.totalSelected?"selected":""}" @click="${this.selectTotal}" tabIndex="${this.totalSelected&&!this.showLegend?"1":"-1"}"> ${this.total?this.formatter(this.total):""} </div> </div> </div> ${this.showLegend?Ee` <div class="pie-chart-legend"> ${this.slices.map(((e,t)=>{const i=this.sliceSelected===t;return Ee` <div class="pie-chart-legend-row ${i?"selected":""}" @click="${this.onSliceClicked(t)}" tabIndex="${i?"0":"-1"}"> <div class="pie-chart-size">${this.formatter(e.value)}</div> <div class="pie-chart-swatch" style="background-color: ${e.color};"></div> <div class="pie-chart-name">${e.title}</div> </div>`}))} <div class="pie-chart-legend-row ${this.totalSelected?"selected":""}" @click="${this.selectTotal}" tabIndex="${this.totalSelected?"0":"-1"}"> <div class="pie-chart-size">${this.formatter(this.total)}</div> <div class="pie-chart-swatch pie-chart-empty-swatch"></div> <div class="pie-chart-name">${Ce(xe.total)}</div> </div> </div> `:""} </div>`;Te(e,this.shadow,{host:this})}onSliceClicked(e){return()=>{this.selectSlice(e)}}selectSlice(e){this.totalSelected=!1,this.sliceSelected=e,this.render()}selectTotal(){this.totalSelected=!0,this.sliceSelected=-1,this.render()}selectAndFocusTotal(){this.selectTotal();const e=this.shadow.querySelector(".pie-chart-legend > :last-child");e&&e.focus()}selectAndFocusSlice(e){this.selectSlice(e);const t=this.shadow.querySelector(`.pie-chart-legend > :nth-child(${e+1})`);t&&t.focus()}focusNextElement(){this.totalSelected?this.selectAndFocusSlice(0):this.sliceSelected===this.slices.length-1?this.selectAndFocusTotal():this.selectAndFocusSlice(this.sliceSelected+1)}focusPreviousElement(){this.totalSelected?this.selectAndFocusSlice(this.slices.length-1):0===this.sliceSelected?this.selectAndFocusTotal():this.selectAndFocusSlice(this.sliceSelected-1)}onKeyDown(e){let t=!1;"ArrowDown"===e.key?(this.focusNextElement(),t=!0):"ArrowUp"===e.key&&(this.focusPreviousElement(),t=!0),t&&(e.stopImmediatePropagation(),e.preventDefault())}getPathStringForSlice(e){let t=e.value/this.total*2*Math.PI;if(!isFinite(t))return;t=Math.min(t,2*Math.PI*.9999);const i=Math.cos(this.lastAngle),s=Math.sin(this.lastAngle);this.lastAngle+=t;const r=Math.cos(this.lastAngle),n=Math.sin(this.lastAngle),o=this.innerR,a=r*o,l=n*o,h=i*o,d=s*o,c=t>Math.PI?1:0;return`M${i},${s} A1,1,0,${c},1,${r},${n} L${a},${l} A${o},${o},0,${c},0,${h},${d} Z`}}m.CustomElements.defineComponent("devtools-perf-piechart",Pe);var ke=Object.freeze({__proto__:null,PieChart:Pe});const De=new CSSStyleSheet;De.replaceSync(".overview-info:not(:empty){display:flex;background:var(--color-background);box-shadow:var(--drop-shadow);padding:3px}.overview-info .frame .time{display:none}.overview-info .frame .thumbnail img{max-width:50vw;max-height:50vh}\n/*# sourceURL=timelineOverviewInfo.css */\n");class Ie extends(e.ObjectWrapper.eventMixin(r.Widget.VBox)){overviewCalculator;overviewGrid;cursorArea;cursorElement;overviewControls;markers;overviewInfo;updateThrottler;cursorEnabled;cursorPosition;lastWidth;windowStartTime;windowEndTime;muteOnWindowChanged;constructor(t){super(),this.element.id=t+"-overview-pane",this.overviewCalculator=new Me,this.overviewGrid=new pe(t,this.overviewCalculator),this.element.appendChild(this.overviewGrid.element),this.cursorArea=this.overviewGrid.element.createChild("div","overview-grid-cursor-area"),this.cursorElement=this.overviewGrid.element.createChild("div","overview-grid-cursor-position"),this.cursorArea.addEventListener("mousemove",this.onMouseMove.bind(this),!0),this.cursorArea.addEventListener("mouseleave",this.hideCursor.bind(this),!0),this.overviewGrid.setResizeEnabled(!1),this.overviewGrid.addEventListener(ve.WindowChangedWithPosition,this.onWindowChanged,this),this.overviewGrid.setClickHandler(this.onClick.bind(this)),this.overviewControls=[],this.markers=new Map,this.overviewInfo=new We(this.cursorElement),this.updateThrottler=new e.Throttler.Throttler(100),this.cursorEnabled=!1,this.cursorPosition=0,this.lastWidth=0,this.windowStartTime=0,this.windowEndTime=1/0,this.muteOnWindowChanged=!1}onMouseMove(e){if(!this.cursorEnabled)return;const t=e,i=e.target;this.cursorPosition=t.offsetX+i.offsetLeft,this.cursorElement.style.left=this.cursorPosition+"px",this.cursorElement.style.visibility="visible",this.overviewInfo.setContent(this.buildOverviewInfo())}async buildOverviewInfo(){const e=this.element.ownerDocument,t=this.cursorPosition,i=await Promise.all(this.overviewControls.map((e=>e.overviewInfoPromise(t)))),s=e.createDocumentFragment(),r=i.filter((e=>null!==e));return s.append(...r),s}hideCursor(){this.cursorElement.style.visibility="hidden",this.overviewInfo.hide()}wasShown(){this.update()}willHide(){this.overviewInfo.hide()}onResize(){const e=this.element.offsetWidth;e!==this.lastWidth&&(this.lastWidth=e,this.scheduleUpdate())}setOverviewControls(e){for(let e=0;e<this.overviewControls.length;++e)this.overviewControls[e].dispose();for(let t=0;t<e.length;++t)e[t].setCalculator(this.overviewCalculator),e[t].show(this.overviewGrid.element);this.overviewControls=e,this.update()}setBounds(e,t){this.overviewCalculator.setBounds(e,t),this.overviewGrid.setResizeEnabled(!0),this.cursorEnabled=!0}setNavStartTimes(e){this.overviewCalculator.setNavStartTimes(e)}scheduleUpdate(){this.updateThrottler.schedule((async()=>{this.update()}))}update(){if(this.isShowing()){this.overviewCalculator.setDisplayWidth(this.overviewGrid.clientWidth());for(let e=0;e<this.overviewControls.length;++e)this.overviewControls[e].update();this.overviewGrid.updateDividers(this.overviewCalculator),this.updateMarkers(),this.updateWindow()}}setMarkers(e){this.markers=e}updateMarkers(){const e=new Map;for(const t of this.markers.keys()){const i=this.markers.get(t),s=Math.round(this.overviewCalculator.computePosition(t));e.has(s)||(e.set(s,i),i.style.left=s+"px")}this.overviewGrid.removeEventDividers(),this.overviewGrid.addEventDividers([...e.values()])}reset(){this.windowStartTime=0,this.windowEndTime=1/0,this.overviewCalculator.reset(),this.overviewGrid.reset(),this.overviewGrid.setResizeEnabled(!1),this.cursorEnabled=!1,this.hideCursor(),this.markers=new Map;for(const e of this.overviewControls)e.reset();this.overviewInfo.hide(),this.scheduleUpdate()}onClick(e){return this.overviewControls.some((t=>t.onClick(e)))}onWindowChanged(e){if(this.muteOnWindowChanged)return;if(!this.overviewControls.length)return;this.windowStartTime=e.data.rawStartValue===this.overviewCalculator.minimumBoundary()?0:e.data.rawStartValue,this.windowEndTime=e.data.rawEndValue===this.overviewCalculator.maximumBoundary()?1/0:e.data.rawEndValue;const t={startTime:this.windowStartTime,endTime:this.windowEndTime};this.dispatchEventToListeners(Re.WindowChanged,t)}setWindowTimes(e,t){e===this.windowStartTime&&t===this.windowEndTime||(this.windowStartTime=e,this.windowEndTime=t,this.updateWindow(),this.dispatchEventToListeners(Re.WindowChanged,{startTime:e,endTime:t}))}updateWindow(){if(!this.overviewControls.length)return;const e=this.overviewCalculator.minimumBoundary(),t=this.overviewCalculator.maximumBoundary()-e,i=e>0,s=i&&this.windowStartTime?Math.min((this.windowStartTime-e)/t,1):0,r=i&&this.windowEndTime<1/0?(this.windowEndTime-e)/t:1;this.muteOnWindowChanged=!0,this.overviewGrid.setWindow(s,r),this.muteOnWindowChanged=!1}}var Re;!function(e){e.WindowChanged="WindowChanged"}(Re||(Re={}));class Me{minimumBoundaryInternal;maximumBoundaryInternal;workingArea;navStartTimes;constructor(){this.reset()}computePosition(e){return(e-this.minimumBoundaryInternal)/this.boundarySpan()*this.workingArea}positionToTime(e){return e/this.workingArea*this.boundarySpan()+this.minimumBoundaryInternal}setBounds(e,t){this.minimumBoundaryInternal=e,this.maximumBoundaryInternal=t}setNavStartTimes(e){this.navStartTimes=e}setDisplayWidth(e){this.workingArea=e}reset(){this.setBounds(0,100)}formatValue(e,i){if(this.navStartTimes){const t=Array.from(this.navStartTimes.values());for(let i=t.length-1;i>=0;i--)if(e>t[i].startTime){e-=t[i].startTime-this.zeroTime();break}}return t.TimeUtilities.preciseMillisToString(e-this.zeroTime(),i)}maximumBoundary(){return this.maximumBoundaryInternal}minimumBoundary(){return this.minimumBoundaryInternal}zeroTime(){return this.minimumBoundaryInternal}boundarySpan(){return this.maximumBoundaryInternal-this.minimumBoundaryInternal}}class ze extends r.Widget.VBox{calculatorInternal;canvas;contextInternal;constructor(){super(),this.calculatorInternal=null,this.canvas=this.element.createChild("canvas","fill"),this.contextInternal=this.canvas.getContext("2d")}width(){return this.canvas.width}height(){return this.canvas.height}context(){if(!this.contextInternal)throw new Error("Unable to retrieve canvas context");return this.contextInternal}calculator(){return this.calculatorInternal}update(){this.resetCanvas()}dispose(){this.detach()}reset(){}async overviewInfoPromise(e){return null}setCalculator(e){this.calculatorInternal=e}onClick(e){return!1}resetCanvas(){this.element.clientWidth&&this.setCanvasSize(this.element.clientWidth,this.element.clientHeight)}setCanvasSize(e,t){this.canvas.width=e*window.devicePixelRatio,this.canvas.height=t*window.devicePixelRatio}}class We{anchorElement;glassPane;visible;element;constructor(e){this.anchorElement=e,this.glassPane=new r.GlassPane.GlassPane,this.glassPane.setPointerEventsBehavior("PierceContents"),this.glassPane.setMarginBehavior("Arrow"),this.glassPane.setSizeBehavior("MeasureContent"),this.visible=!1,this.element=r.Utils.createShadowRootWithCoreStyles(this.glassPane.contentElement,{cssFile:[De],delegatesFocus:void 0}).createChild("div","overview-info")}async setContent(e){this.visible=!0;const t=await e;this.visible&&(this.element.removeChildren(),this.element.appendChild(t),this.glassPane.setContentAnchorBox(this.anchorElement.boxInWindow()),this.glassPane.isShowing()||this.glassPane.show(this.anchorElement.ownerDocument))}hide(){this.visible=!1,this.glassPane.hide()}}var Ae=Object.freeze({__proto__:null,TimelineOverviewPane:Ie,get Events(){return Re},TimelineOverviewCalculator:Me,TimelineOverviewBase:ze,OverviewInfo:We});export{A as ChartViewport,_ as FilmStripView,M as FlameChart,v as Font,j as GCActionDelegate,Q as LineLevelProfile,ie as LiveHeapProfile,de as NetworkPriorities,ye as OverviewGrid,ke as PieChart,T as TimelineGrid,Ae as TimelineOverviewPane};
